Hive_Container::factory PHP Method

factory() public static method

$container = Hive_Container::factory($owner, $relation);
public static factory ( Hive $owner = NULL, Hive_Relation $relation = NULL ) : Hive_Container
$owner Hive
$relation Hive_Relation
return Hive_Container
    public static function factory(Hive $owner = NULL, Hive_Relation $relation = NULL)
    {
        $container = new Hive_Container();
        if ($owner) {
            // Store the owner that created this container
            $container->owner($owner);
        }
        if ($relation) {
            // Store the relation that created this container
            $container->relation($relation);
        }
        return $container;
    }

Usage Example

Beispiel #1
0
 public function read(Hive $parent)
 {
     $container = Hive_Container::factory($parent, $this);
     if ($parent->prepared()) {
         // Create child model
         $child = Hive::factory($this->model);
         // Import meta data
         $parent_meta = Hive::meta($parent);
         $child_meta = Hive::meta($child);
         // Create a new query
         $query = $child->query_select();
         // Apply JOINs
         $query->join($this->table);
         foreach ($this->using['child'] as $local => $remote) {
             $query->on($child_meta->column($local), '=', "{$this->table}.{$remote}");
         }
         foreach ($this->using['parent'] as $local => $remote) {
             $query->where("{$this->table}.{$remote}", '=', $parent->{$local});
         }
         // Return the result as an array of child objects
         $results = $query->as_object($child)->execute($parent_meta->db)->as_array($this->key);
         $container->values($results);
     }
     return $container;
 }
All Usage Examples Of Hive_Container::factory