Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 17, 2021
1 parent af124fc commit a931134
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,15 @@ protected function setLimitOrder(Model $model, Query $query)
}

/**
* Will apply a condition defined inside $condition or $model->scope() onto $query.
* Will apply $model->scope() conditions onto $query.
*/
public function initQueryConditions(Model $model, Query $query, Model\Scope\AbstractScope $condition = null): void
public function initQueryConditions(Model $model, Query $query): void
{
$condition = $condition ?? $model->scope();
$this->_initQueryConditions($query, $model->scope());
}

private function _initQueryConditions(Query $query, Model\Scope\AbstractScope $condition = null): void
{
if (!$condition->isEmpty()) {
// peel off the single nested scopes to convert (((field = value))) to field = value
$condition = $condition->simplify();
Expand All @@ -384,7 +387,7 @@ public function initQueryConditions(Model $model, Query $query, Model\Scope\Abst
$expression = $condition->isOr() ? $query->orExpr() : $query->andExpr();

foreach ($condition->getNestedConditions() as $nestedCondition) {
$this->initQueryConditions($model, $expression, $nestedCondition);
$this->_initQueryConditions($expression, $nestedCondition);
}

$query->where($expression);
Expand Down

0 comments on commit a931134

Please sign in to comment.