示例#1
0
 public function value($value)
 {
     if (empty($value) and $this->empty) {
         return array();
     } elseif (is_object($value)) {
         $model = Sprig::factory($this->model);
         // Assume this is a Database_Result object
         $value = $value->as_array(NULL, $model->pk());
     } else {
         // Value must always be an array
         $value = (array) $value;
     }
     if ($value) {
         // Convert objects in array to IDs
         foreach ($value as $k => $item) {
             if (is_object($item)) {
                 $value[$k] = $item->{$item->pk()};
             }
         }
         // Combine the value to make a mirrored array
         $value = array_combine($value, $value);
         foreach ($value as $id) {
             // Convert the value to the proper type
             $value[$id] = parent::value($id);
         }
     }
     return $value;
 }
示例#2
0
文件: hasone.php 项目: vitch/sprig
 public function set($value)
 {
     if ($value instanceof Sprig) {
         $value = $value->{$value->pk()};
     }
     return parent::set($value);
 }
示例#3
0
文件: hasmany.php 项目: vitch/sprig
 public function set($value)
 {
     return parent::set((array) $value);
 }