public function refSQL($mode = null) { if ($mode == 'model') { /** @type SQL_Model $m */ $m = $this->add($this->model_name); return $m->addCondition($this->their_field, $this->owner->getElement($this->our_field)); } $this->restoreConditions(); return $this->model->addCondition($this->their_field, $this->owner->getElement($this->our_field)); }
public function hasOne($model, $our_field = UNDEFINED, $field_class = UNDEFINED) { // @todo Should check field types. There is some kind of mix of SQL fields and base fields /** @type Field_SQL_HasOne $field */ $field = $this->model->hasOne($model, $our_field, $field_class); $field->table($this->joinAlias); /** @type Field_SQL_HasOne $foreign_field */ $foreign_field = $this->model->getElement($field->getForeignFieldName()); $foreign_field->table($this->joinAlias); return $field; }
/** * Prepare create-table action * * @param SQL_Model $model * * @return void */ function createTable(\SQL_Model $model) { if ($this->is_default_id_field) { // default ID field $type = 'integer'; $auto = 'auto_increment'; } else { // custom ID field $field = $model->getElement($model->id_field); $type = $this->mapFieldType($field); $auto = ''; } // register action $this->actions['create-table'] = array('template' => $this->templates['create-table'], 'tags' => array('table' => $model->table, 'field' => $model->id_field, 'type' => $type, 'auto_incr' => $auto, 'engine' => $this->engine)); }