/** * Returns an array of beans. Pass a type and a series of ids and * this method will bring you the corresponding beans. * * important note: Because this method loads beans using the load() * function (but faster) it will return empty beans with ID 0 for * every bean that could not be located. The resulting beans will have the * passed IDs as their keys. * * @param string $type type of beans * @param array $ids ids to load * * @return array */ public function batch($type, $ids) { if (!$ids) { return array(); } $collection = array(); try { $rows = $this->writer->queryRecord($type, array('id' => $ids)); } catch (RedBean_Exception_SQL $e) { $this->handleException($e); $rows = FALSE; } $this->stash[$this->nesting] = array(); if (!$rows) { return array(); } foreach ($rows as $row) { $this->stash[$this->nesting][$row['id']] = $row; } foreach ($ids as $id) { $collection[$id] = $this->load($type, $id); } $this->stash[$this->nesting] = NULL; return $collection; }