Skip to content

Commit

Permalink
FilterProcessor: Inject column expressions directly into filters
Browse files Browse the repository at this point in the history
fixes #75
  • Loading branch information
nilmerg committed Oct 12, 2022
1 parent 0b76de0 commit 23431d0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Compat/FilterProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ipl\Orm\Relation;
use ipl\Orm\UnionQuery;
use ipl\Sql\Expression;
use ipl\Sql\ExpressionInterface;
use ipl\Sql\Filter\Exists;
use ipl\Sql\Filter\NotExists;
use ipl\Stdlib\Contract\Filterable;
Expand Down Expand Up @@ -128,6 +129,20 @@ protected function requireAndResolveFilterColumns(Filter\Rule $filter, Query $qu
throw new InvalidColumnException($columnName, $subject);
}

$columns = $subject->getColumns();
if (isset($columns[$columnName]) && $columns[$columnName] instanceof ExpressionInterface) {
$expression = clone $columns[$columnName];
$expression->setColumns($resolver->qualifyColumns(
$resolver->requireAndResolveColumns(
$columns[$columnName]->getColumns(),
$subject
),
$subject
));

$filter->setColumn($query->getDb()->getQueryBuilder()->buildExpression($expression));
}

if ($relationPath !== $baseTable) {
$query->utilize($relationPath);
$this->madeJoins[$relationPath][] = $filter;
Expand Down

0 comments on commit 23431d0

Please sign in to comment.