I am new to Symfony
and I have had a problem with a query. I have two entities that are not directly related: vacation and absence and both have an 'approved' field that is set to 0 by default. What I want is to retrieve all the records whose field approved
is set to 0. I use this query:
SELECT v, a
FROM AppBundle:Vacation v, AppBundle:Absence a
WHERE v.approved = 0 AND a.approved = 0');
And it works perfectly as long as there is at least one record with the field approved
at 0 in both. If in one of them there is no record at 0, it does not return anything. And if I put a OR
instead of AND
in those same circumstances, it returns all the records even if they are at 1. Is there any way to get the result with a single query?
Thanks in advance.
As they are not related, what you can do is make the queries separately, and 'join' the response.
In fact, you can do it through the ORM, without the need to do the SQL query:
Now, in $result, you will have an ArrayCollection with the result of the two queries, and in the event that the record does not exist in one, you will obtain the results of the other.
Greetings, I hope it works for you.