-1

I have two models: Users and Groups with many-to-many relationship. So I need select all users, which hasn't group. It must me realize by DQL.

Ok, something more information. I work in symfony 2 with sonata admin bundle. In my list view I want to show users which has no relationship with group. For example: When admin in admin panel create user, he choose group for this user. But when user register from frontend, this user has no any groups. So, I want to see all this users without groups. In sonata admin bundle in Admin classs I can inherit createQuery method, where I can write my own DQL query. As an example:

public function createQuery($context = 'list')
{
    $query = parent::createQuery($context);
    $query->andWhere('o.admin = TRUE');
    $query->orderBy('o.loginDate', 'DESC');

    return $query;
}

So, in my case I want choose users without groups, something like this:

public function createQuery($context = 'list')
{
    $query = parent::createQuery($context);
    $query->addSelect('g');
    $query->leftJoin('o.groupList', 'g');

    // here I need some DQL which chose users without groups

    return $query;
}

So, now can anybody help?

  • possible duplicate of [Can I use "ON" keyword in DQL or do I need to use Native Query?](http://stackoverflow.com/questions/8748664/can-i-use-on-keyword-in-dql-or-do-i-need-to-use-native-query) – hakre Jun 13 '12 at 10:50
  • Please describe your problem a little bit more. This is a programming website, for example can you show your code? It must not need to work, but this should make more clear into which problem in specific you run into. – hakre Jun 13 '12 at 10:52

1 Answers1

1

If you have a relationship into user, like a groups property being an ArrayCollection, then you could simply get users where count(u.groups) = 0 or something like that?

PEM
  • 1,948
  • 14
  • 13