/** * Loads and returns a series of beans of type $type. * The beans are loaded all at once. * The beans are retrieved using their primary key IDs * specified in the second argument. * @throws RedBean_Exception_Security $exception * @param string $type * @param array $ids * @return array $beans */ public function batch($type, $ids) { if (!$ids) { return array(); } $collection = array(); try { $rows = $this->writer->selectRecord($type, $ids); } catch (RedBean_Exception_SQL $e) { if ($e->getSQLState() != "42S02" && $e->getSQLState() != "42S22") { throw $e; } $rows = false; } $this->stash = array(); if (!$rows) { return array(); } foreach ($rows as $row) { $this->stash[$row[$this->writer->getIDField($type)]] = $row; } foreach ($ids as $id) { $collection[$id] = $this->load($type, $id); } $this->stash = NULL; return $collection; }
/** * Loads and returns a series of beans of type $type. * The beans are loaded all at once. * The beans are retrieved using their primary key IDs * specified in the second argument. * @throws RedBean_Exception_Security $exception * @param string $type * @param array $ids * @return array $beans */ public function batch($type, $ids) { if (!$ids) { return array(); } $collection = array(); try { $idfield = $this->writer->getIDField($type); $rows = $this->writer->selectRecord($type, array($idfield => $ids)); } catch (RedBean_Exception_SQL $e) { if (!$this->writer->sqlStateIn($e->getSQLState(), array(RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN, RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE))) { throw $e; } $rows = false; } $this->stash = array(); if (!$rows) { return array(); } foreach ($rows as $row) { $this->stash[$row[$this->writer->getIDField($type)]] = $row; } foreach ($ids as $id) { $collection[$id] = $this->load($type, $id); } $this->stash = NULL; return $collection; }