I have written a query
WHERE e.foo = 'example' OR e.f.bar = 'example'
Now I found that all entities with e.f == null
aren’t found. Probably there is done a inner join.
After this I tried two alternatives
WHERE e.foo = 'example'
OR e.f IN (SELECT f FROM ex_F f WHERE f.bar = 'example')
Although this works in plain SQL, it gives me the same entities as the first query. So only the next query with explicit LEFT JOIN
gave me the expected results.
SELECT e FROM ex_E e
LEFT JOIN e.f f
WHERE e.foo = 'example' OR f.bar = 'example'
In my scenario many entities with e.foo == 'example'
have no e.f
so that we found this quite fast. But I am concerned that in other queries we miss this case.
Is there a way to achieve this with a better readable query? Do you have an idea why the second query doesn’t give entites with e.f == null
?