I have two entites
Order
oneToMany:
statuses:
targetEntity: \Status
mappedBy: order
Status
manyToOne:
order:
targetEntity: \Order
inversedBy: status
fields:
code:
type:integer
As you can see - one order can have more that one status at a time (statuses like 'has been shipped', 'has been paid for etc.').
I want to write a query that fetch all my Orders that do NOT have a status of 6. I'm finding it hard to get my head round this.
Assume that I have three orders. The all have a status of '1' (new), and ONE of those orders additionally has a status of '6' (under review). I want to retrieve only the two orders that do NOT have a status of 6.
Writing the query like so..
$qb->select('o')
->from('MyOrderBundle:Order', 'o')
->innerJoin('o.statuses', 'st')
->where(
$qb->expr()->not(
$qb->expr()->eq('st.code', 6)
)
);
Excludes the status row of 6 from the SQL generated, but still includes the order in the result set (because the status row where the code=1 matches the condition of not being equal to 6). I need to be able to say "Exclude from my result set any entity that has an association like {something}". Is there a DQL keyword that can help me here?
-Cross posting on the doctrine user group and will update answers In both place if I find a solution.