/** * * @param RedBean_OODBBean $parent * @return array $childObjects */ public function children(RedBean_OODBBean $parent) { try { $ids = $this->adapter->getCol("SELECT id FROM\n\t\t\t`" . $parent->getMeta("type") . "`\n\t\t\tWHERE `" . $this->property . "` = " . intval($parent->id) . "\n\t\t"); } catch (RedBean_Exception_SQL $e) { return array(); } return $this->oodb->batch($parent->getMeta("type"), $ids); }
/** * Returns all the nodes that have been attached to the specified * parent node. * @param RedBean_OODBBean $parent * @return array $childObjects */ public function children(RedBean_OODBBean $parent) { $idfield = $this->writer->getIDField($parent->getMeta("type")); try { $ids = $this->writer->selectByCrit($idfield, $parent->getMeta("type"), $this->property, intval($parent->{$idfield})); } catch (RedBean_Exception_SQL $e) { return array(); } return $this->oodb->batch($parent->getMeta("type"), $ids); }
/** * Loads a batch of beans all at once. * This function first inspects the cache; if every element in the batch * is available in the cache, the function will return the collected beans * from the cache. If one or more beans cannot be found, the function will * ask oodb for the beans and update the cache. * @param string $type * @param integer $ids * @return array $beans */ public function batch($type, $ids) { $idfield = $this->writer->getIDField($type); $collect = array(); foreach ($ids as $id) { $bean = $this->fetchFromCacheByTypeID($type, $id); if ($bean) { $collect[$id] = $bean; } } if (count($collect) == count($ids)) { return $collect; } else { $beans = $this->oodb->batch($type, $ids); foreach ($beans as $bean) { $this->putInCache($bean); } return $beans; } }
/** * * @param RedBean_OODBBean $parent * @return array $childObjects */ public function children(RedBean_OODBBean $parent) { $idfield = $this->writer->getIDField($parent->getMeta("type")); try { /* $ids = $this->adapter->getCol("SELECT `".$idfield."` FROM `".$parent->getMeta("type")."` WHERE `".$this->property."` = ".intval( $parent->$idfield )." "); */ /* $ids = $this->adapter->getCol($this->writer->buildSimpleQuery( "select",array($idfield),$parent->getMeta("type"), array("name"=>$this->property, "value"=>intval($parent->$idfield), "operator"=>"=","structure"=>"") )); */ $ids = $this->writer->selectByCrit($idfield, $parent->getMeta("type"), $this->property, intval($parent->{$idfield})); } catch (RedBean_Exception_SQL $e) { return array(); } return $this->oodb->batch($parent->getMeta("type"), $ids); }
/** * Returns an array of beans. Pass a type and a series of ids and * this method will bring you the correspondig 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 $beans resulting beans (may include empty ones) */ public static function batch($type, $ids) { return self::$redbean->batch($type, $ids); }
asrt(isset($movie->movie_id), true); $movie->name = "movie 1"; $movieid = $redbean2->store($movie); asrt($movieid > 0, true); $columns = array_keys($writer->getColumns("movie")); asrt(in_array("movie_id", $columns), true); asrt(in_array("id", $columns), false); $movie2 = $redbean2->dispense("movie"); asrt(isset($movie2->movie_id), true); $movie2->name = "movie 2"; $movieid2 = $redbean2->store($movie2); $movie1 = $redbean2->load("movie", $movieid); asrt($movie->name, "movie 1"); $movie2 = $redbean2->load("movie", $movieid2); asrt($movie2->name, "movie 2"); $movies = $redbean2->batch("movie", array($movieid, $movieid2)); asrt(count($movies), 2); asrt($movies[$movieid]->name, "movie 1"); asrt($movies[$movieid2]->name, "movie 2"); $toolbox2 = new RedBean_ToolBox($redbean2, $adapter, $writer2); $a2 = new RedBean_AssociationManager($toolbox2); $a2->associate($movie1, $movie2); $movies = $a2->related($movie1, "movie"); asrt(count($movies), 1); asrt((int) $movies[0], (int) $movieid2); $movies = $a2->related($movie2, "movie"); asrt(count($movies), 1); asrt((int) $movies[0], (int) $movieid); $genre = $redbean2->dispense("genre"); $genre->name = "western"; $a2->associate($movie, $genre);
/** * @see RedBean_Instance::batch * * Alias for batch(). Batch method is older but since we added so-called *All * methods like storeAll, trashAll, dispenseAll and findAll it seemed logical to * improve the consistency of the Facade API and also add an alias for batch() called * loadAll. * * @param string $type type of beans * @param array $ids ids to load * * @return array */ public function loadAll($type, $ids) { return $this->redbean->batch($type, $ids); }