Bug #32539
closedUsing a constraint or ordering on a property on the right side of a m:n relation causes records from the left side with no related elements (0 cardinality) to not show
0%
Description
On the following model:
- Model1
- Model2
- Model1.related is a m:n relation to Model2. Cardinality is 0..n
Example data:
- Model 1{a} -> "name" => "some value", "related" => Model2{a}
- Model 1{b} -> "name" => "some value"
- Model 2{a} -> "name" => "some value"
If you run a query on Extbase that runs a constraint on any property of Model2 through Model1:
(inside Model1 repository class)
$query = $this->createQuery(); $query->matching( $query->logicalOr( $query->like('name', 'some value'), $query->like('related.name', 'some value'), ) )->execute();
You will get only Model1 results which are related to matching Model2 rows, but according to the "logicalOr" you must get also Model1 results matching the criteria which are not related to Model2.
You currently get:
- Model 1{a}
But you should get:
- Model 1{a}
- Model 1{b}
By analysis of the generated SQL the problem is caused by the "enableFields" (the joins are ok):
The current generated SQL query part from the enableFields: AND tx_myext_domain_model_model2.deleted=0 AND [....]
...which forces elements from Model2 to be present on the relation.
This would be the right way: AND (tx_myext_domain_model_model2.uid IS NULL OR (tx_myext_domain_model_model2.deleted=0 AND [....]))
In the latter case we check wether the LEFT JOIN is not getting any values from Model2 and in that case don't apply the enableFields for Model2 on that row.
Files