Example #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));
 }
Example #2
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);
 }
Example #3
0
 /**
  * @return \Notadd\Foundation\Database\Query\Builder
  */
 public function getBaseQuery()
 {
     return $this->query->getQuery();
 }
Example #4
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @return \Notadd\Foundation\Database\Eloquent\Builder
  */
 protected function setKeysForSaveQuery(Builder $query)
 {
     $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery());
     return $query;
 }
Example #5
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @return \Notadd\Foundation\Database\Eloquent\Builder
  */
 protected function useWithTrashed(Builder $query)
 {
     if ($this->withTrashed && $query->getMacro('withTrashed') !== null) {
         return $query->withTrashed();
     }
     return $query;
 }
Example #6
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @return \Notadd\Foundation\Database\Eloquent\Builder
  */
 protected function setKeysForSaveQuery(Builder $query)
 {
     $query->where($this->foreignKey, $this->getAttribute($this->foreignKey));
     return $query->where($this->otherKey, $this->getAttribute($this->otherKey));
 }
Example #7
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @return \Notadd\Foundation\Database\Eloquent\Builder
  */
 protected function setKeysForSaveQuery(Builder $query)
 {
     $query->where($this->morphType, $this->morphClass);
     return parent::setKeysForSaveQuery($query);
 }