저자: Woody Gilk (woody@wingsc.com)
상속: extends ArrayObject
예제 #1
0
 /**
  * Create a new container.
  *
  *     $container = Hive_Container::factory($owner, $relation);
  *
  * @param   Hive           owner of this container
  * @param   Hive_Relation  relation that generated this container
  * @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;
 }
예제 #2
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;
 }
예제 #3
0
파일: hasmany.php 프로젝트: shadowhand/hive
 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($parent_meta->table);
         foreach ($this->using as $parent_field => $child_field) {
             $query->on($parent_meta->column($parent_field), '=', $child_meta->column($child_field));
         }
         // Apply parent WHERE conditions
         $parent->query_conditions($query);
         // 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;
 }