Exemplo n.º 1
0
 /**
  * Create a new has many relationship instance.
  *
  * @param  \Nova\Database\ORM\Builder  $query
  * @param  \Nova\Database\ORM\Model  $parent
  * @param  string  $name
  * @param  string  $table
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @param  string  $relationName
  * @param  bool   $inverse
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false)
 {
     $this->inverse = $inverse;
     $this->morphType = $name . '_type';
     $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass();
     parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName);
 }
Exemplo n.º 2
0
 /**
  * Create a new has many relationship instance.
  *
  * @param  \Nova\Database\ORM\Builder  $query
  * @param  \Nova\Database\ORM\Model  $parent
  * @param  string  $type
  * @param  string  $id
  * @param  string  $localKey
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $type, $id, $localKey)
 {
     $this->morphType = $type;
     $this->morphClass = $parent->getMorphClass();
     parent::__construct($query, $parent, $id, $localKey);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }