/** * Set the base constraints on the relation query. * * @return void */ public function addConstraints() { $parentTable = $this->parent->getTable(); $this->setJoin(); if (static::$constraints) { $this->query->where($parentTable . '.' . $this->firstKey, '=', $this->farParent->getKey()); } }
/** * Save a new model and attach it to the parent model. * * @param \Nova\Database\ORM\Model $model * @param array $joining * @param bool $touch * @return \Nova\Database\ORM\Model */ public function save(Model $model, array $joining = array(), $touch = true) { $model->save(array('touch' => false)); $this->attach($model->getKey(), $joining, $touch); return $model; }
/** * Associate the model instance to the given parent. * * @param \Nova\Database\ORM\Model $model * @return \Nova\Database\ORM\Model */ public function associate(Model $model) { $this->parent->setAttribute($this->foreignKey, $model->getKey()); $this->parent->setAttribute($this->morphType, $model->getMorphClass()); return $this->parent->setRelation($this->relation, $model); }