예제 #1
0
 public function read(Hive $parent)
 {
     $child = Hive::factory($this->model, array($this->parent => $parent));
     if ($parent->prepared()) {
         foreach ($this->using as $local => $remote) {
             $child->{$remote} = $parent->{$local};
         }
     }
     if ($this->conditions) {
         foreach ($this->conditions as $remote => $value) {
             $child->{$remote} = $value;
         }
     }
     return $child;
 }
예제 #2
0
 public function as_array(Hive $parent)
 {
     $result = array();
     if ($parent->prepared()) {
         $child = Hive::factory($this->model);
         list($id, $fk) = $this->field;
         $query = DB::select(array($fk, $id))->from($this->table)->as_object(FALSE);
         foreach ($this->using as $local => $remote) {
             $query->where("{$this->table}.{$remote}", '=', $parent->{$local});
         }
         $result = $query->execute(Hive::meta($parent)->db)->as_array($id, $id);
         $field = Hive::meta($child)->fields[$id];
         foreach ($result as $value) {
             // Type cast the values
             $result[$value] = $field->value($value);
         }
     }
     return $result;
 }