public mergeModelDefinedRelationConstraints ( |
||
$relation | ||
return |
public function mergeModelDefinedRelationConstraints(Builder $relation)
{
$removedScopes = $relation->removedScopes();
$relationQuery = $relation->getQuery();
$whereBindings = Arr::get($relationQuery->getRawBindings(), 'where', []);
// Here we have some relation query and the original relation. We need to copy over any
// where clauses that the developer may have put in the relation definition function.
// We need to remove any global scopes that the developer already removed as well.
return $this->withoutGlobalScopes($removedScopes)->mergeWheres($relationQuery->wheres, $whereBindings);
}
/** * Add the "has" condition where clause to the query. * * @param \Illuminate\Database\Eloquent\Builder $hasQuery * @param \Illuminate\Database\Eloquent\Relations\Relation $relation * @param string $operator * @param int $count * @param string $boolean * @return \Illuminate\Database\Eloquent\Builder|static */ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, $count, $boolean) { $hasQuery->mergeModelDefinedRelationConstraints($relation->getQuery()); if ($this->shouldRunExistsQuery($operator, $count)) { $not = $operator === '<' && $count === 1; return $this->addWhereExistsQuery($hasQuery->toBase(), $boolean, $not); } return $this->whereCountQuery($hasQuery->toBase(), $operator, $count, $boolean); }