I have two entities ServeApp and App. They both have a relation to AppPage. I'm trying to get ServeApps that have AppPages which App does not have.
So ServeApps.appPages should not contain the same AppPages that Apps.appPages contains.
I'm trying to write a DQL query that would be something similar to
SELECT ServeApps WHERE ServeApps.appPages NOT IN Apps.appPages
but I'm at a loss how to go about it. I tried $queryBuilder->whereNotIn() but I guess that method doesn't exists?
Any help would be appreciated :)
EDIT:
I ended up changing my approach. Since the AppPages had a many to many relationship to both ServeApps and Apps, I did the following:
SELECT sa FROM ServeApps sa WHERE sa.id NOT IN (
SELECT ssa.id FROM AppPage ap JOIN ap.serveApps ssa WHERE ap.id = :apppage
)
I changed my logic to take out the Apps from the equation and then I checked it differently. I also had a version where I resulted to raw SQL for counting the ServeApps.
Your where-not-in statement should look like this
$queryBuilder->where($queryBuilder->expr()->notIn('alias.field', $arrayOfValues));
You can find a reference of all expressions in Doctrine's documentation.
As a side note, a where-in statement should look like this
$queryBuilder->where($queryBuilder->expr()->in('alias.field', $arrayOfValues));