R
R
ruslanyugov2022-03-10 13:20:40
MySQL
ruslanyugov, 2022-03-10 13:20:40

How to form query in symfony doctrine with ManyToMany field?

Hello!

There is an entity Chat
, it has a profile field of the ManyToMany type associated with the Profile entity

. You need to find a Chat in which there are necessarily several Profiles.
It is necessary that all transmitted be in this Chat.
I try like this, but it turns out that it checks one of the matches, not all.

public function findByTwoUsers(array $profiles)
    {

        return $this->createQueryBuilder('c')
            ->andWhere(':users MEMBER OF c.profile')
            ->setParameter('users', $profiles)
            ->getQuery()->getOneOrNullResult();

    }


How to do it right?
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question