Example #1
0
File: Field.php Project: atk4/atk4
 /**
  * Get the value of the field of a loaded model. If model is not loaded
  * will return default value instead.
  *
  * @return mixed current value of a field
  */
 public function get()
 {
     if ($this->owner->loaded() || isset($this->owner->data[$this->short_name])) {
         return $this->owner->get($this->short_name);
     }
     return $this->defaultValue();
 }
Example #2
0
File: Many.php Project: atk4/atk4
 public function ref($mode = null)
 {
     if (!$this->owner->loaded()) {
         throw $this->exception('Model must be loaded before traversing reference');
     }
     if ($mode == 'model') {
         /** @type SQL_Model $m */
         $m = $this->add($this->model_name);
         return $m->addCondition($this->their_field, $this->owner->get($this->our_field));
     }
     $this->restoreConditions();
     $this->model->unload();
     return $this->model->addCondition($this->their_field, $this->owner->get($this->our_field));
 }