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)); }
/** * Get value of this field formatted for SQL. Redefine if you need to convert. * * @return mixed */ public function getSQL() { $val = $this->owner->get($this->short_name); if ($this->type == 'boolean') { $val = $this->getBooleanValue($val); } if ($val == '' && !$this->mandatory && ($this->listData || $this instanceof Field_Reference) && $this->type != 'boolean') { $val = null; } return $val; }
public function beforeInsert($m, $q) { // Insert related table data and add ID into the main query // TODO: handle cases when $this->m1 != $this->owner->table?:$this->owner->table_alias if ($this->delete_behaviour == 'ignore') { return; } if ($this->owner->hasElement($this->m2) && $this->owner->get($this->m2) !== null) { return; // using existing element } $this->dsql->set($this->f2, null); $this->id = $this->dsql->insert(); if ($this->relation) { $q = $this->relation->dsql; } $q->set($this->m2, $this->id); }