diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index cb30abb..629549b 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -1023,6 +1023,7 @@ class CRUDComponent extends Component } } if (!empty($params['relatedFilters'])) { + // $query->group("{$this->TableAlias}.id"); foreach ($params['relatedFilters'] as $filter => $filterValue) { $activeFilters[$filter] = $filterValue; $filterParts = explode('.', $filter); @@ -1066,6 +1067,9 @@ class CRUDComponent extends Component return $query->where([$modelAlias . '.id IN' => $subQuery]); } + // FIXME: Adding related condition with association having `through` setup might include duplicate in the result set + // We should probably rely on `innerJoinWith` and perform deduplication via `distinct` + // Or grouping by primary key for the main model (however this is not optimal/efficient/clean) protected function setNestedRelatedCondition($query, $filterParts, $filterValue) { $modelName = $filterParts[0];