0

I use symfony 1.4.11 with doctrine.This is one of my tables:

Subscriptions:
  connection: doctrine
  tableName: subscriptions
  columns:
    user_id: { type: integer(4), primary: true }
    category_id:  { type: integer(4), primary: true }
  relations:
    sfGuardUser: { onDelete: CASCADE, local: user_id,  foreign: id }
    Categories: { onDelete: CASCADE, local: category_id, foreign: category_id }

I need to get all user_id from this table.

I make :

 public function getSubscriptionsUser()
  {
    $q = $this->createQuery('a')
        ->select ('a.user_id');

   return $q-> execute();
  }

But if the user is subscribed to several categories, its id will be repeated several times. Is it possible to extract only unique id of user? If user have id = 1 , and it is repeated 10 times,in result I will have only "1" , but no "1 1 1 1 1 1 1 1 1 1" :-) Thank you!

denys281
  • 2,004
  • 2
  • 19
  • 38

1 Answers1

3

This should work out for you:

$q = $this->createQuery('a')
    ->select ('distinct(a.user_id) as user_id');
Dziamid
  • 11,225
  • 12
  • 69
  • 104