Esempio 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);
 }
Esempio n. 2
0
 /**
  * Create a new relation instance.
  *
  * @param  \Nova\Database\ORM\Builder  $query
  * @param  \Nova\Database\ORM\Model  $parent
  * @return void
  */
 public function __construct(Builder $query, Model $parent)
 {
     $this->query = $query;
     $this->parent = $parent;
     $this->related = $query->getModel();
     $this->addConstraints();
 }
Esempio n. 3
0
 /**
  * Add the constraints for a relationship count query.
  *
  * @param  \Nova\Database\ORM\Builder  $query
  * @param  \Nova\Database\ORM\Builder  $parent
  * @return \Nova\Database\ORM\Builder
  */
 public function getRelationCountQuery(Builder $query, Builder $parent)
 {
     $query->select(new Expression('count(*)'));
     $otherKey = $this->wrap($query->getModel()->getTable() . '.' . $this->otherKey);
     return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey));
 }