Esempio n. 1
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @param \Notadd\Foundation\Database\Eloquent\Builder $parent
  * @return \Notadd\Foundation\Database\Eloquent\Builder
  */
 public function getRelationCountQueryForSelfRelation(Builder $query, Builder $parent)
 {
     $query->select(new Expression('count(*)'));
     $query->from($query->getModel()->getTable() . ' as ' . ($hash = $this->getRelationCountHash()));
     $key = $this->wrap($this->getQualifiedParentKeyName());
     return $query->where($hash . '.' . $this->getPlainForeignKey(), '=', new Expression($key));
 }
Esempio n. 2
0
 /**
  * Relation constructor.
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @param \Notadd\Foundation\Database\Eloquent\Model $parent
  */
 public function __construct(Builder $query, Model $parent)
 {
     $this->query = $query;
     $this->parent = $parent;
     $this->related = $query->getModel();
     $this->addConstraints();
 }
Esempio n. 3
0
 /**
  * MorphToMany constructor.
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @param \Notadd\Foundation\Database\Eloquent\Model $parent
  * @param string $name
  * @param string $table
  * @param string $foreignKey
  * @param string $otherKey
  * @param string $relationName
  * @param bool $inverse
  */
 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);
 }