A
A
Alexey Anisimov2015-12-21 13:59:52
symfony
Alexey Anisimov, 2015-12-21 13:59:52

How, using Symfony 2/3 + Doctrine, to get entities that do not have a Many-To-One relationship?

Good afternoon.
There are 2 entities: Region and User. One region can have multiple users, a user can only have one region.
How to get through QueryBuilder users who do not have a region set?

public function findUsersWithoutRegion()
    {
        $query = $this->createQueryBuilder('u')
            ->where('u.region = :region')
            ->setParameter('region', null)
            ->orderBy('u.title')
            ->getQuery();
        return $query->getResult();
    }

So it doesn't output anything. If instead of null you pass the id of the region, then it will display the users of the region.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-12-21
@AnisimovAM

where('u.region IS NULL')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question