Esempio n. 1
0
 /**
  * Set value
  */
 public function setValueOut($value = null)
 {
     if ($value == null) {
         $value = [];
     }
     $c = new Collection($value);
     $c->setModel($this);
     parent::setValueOut($c);
 }
Esempio n. 2
0
 /**
  * Set value out
  *
  * @param mixed $value
  */
 public function setValueOut($value = null)
 {
     if (!$value) {
         return;
     }
     $field = $this->getSchema()->getFieldRelationByModel($value);
     if (!$field) {
         throw new \Exception("Couldn't find field of relations BelongsToOne");
     }
     # Add "stack to persist"
     # Remove "old relation"
     $old_value = $this->getObjectModel()->getField($this->getSchema()->getName())->getValue();
     if ($old_value) {
         $old_value->{$field} = null;
         $value->addPersistStack('save', $old_value);
     }
     # Add new relation
     $value->{$field} = $this->getObjectModel();
     # $value -> {$field} Remove connection;
     parent::setValueOut($value);
 }