简体   繁体   中英

Doctrine query builder and manytomany

I have a simple problem.

I have some users. I have some contacts

One User can have some Contacts. One Contact may be owned by many Users.

A simple ManyToMany relation.

User <-> user_contact <-> Contact

How can I build a query that will return something like :

All Contacts not owned by a user. Those contacts may be owned by another User or not.

Thanks.

The MEMBER OF option will do the magic.

I think you're looking for something like this:

$em->createQuery("select c from Contract c where :userId NOT MEMBER OF c.Users")
   ->setParameter("groupId", <<YOUR_USER_ENTITY_OR_USER_ID>>)
   ->getResult();

Ofcourse I don't know your entities, but I think this will give you some idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM