Reynier
Reynier

Reputation: 2478

Stuck trying to get only users with same idempresa

In my application (developed with Symfony 1.4 and Doctrine) I'm trying to get all users based on idempresa of the user logged in. idempresa is in a sf_guard_user_profiletable and this is the schema for that:

SfGuardUserProfile:
  connection: doctrine
  tableName: sf_guard_user_profile
  columns:
    id: { type: integer(8), primary: true }
    user_id: { type: integer(8), primary: false }
    idempresa: { type: integer(4), primary: false }
  relations:
    User:
      local: user_id
      class: sfGuardUser
      type: one
      foreignType: one
      foreignAlias: SfGuardUserProfile
      onDelete: CASCADE
      onUpdate: CASCADE

I'm trying with this query:

Doctrine_Core::getTable('sfGuardUser')
   ->createQuery('u')
   ->leftJoin('u.Profile p')
   ->where('idempresa = ?', $id_empresa)
   ->execute();

But get this error:

Unknown relation alias Profile

What is wrong in my code?

Upvotes: 0

Views: 33

Answers (1)

Michal Trojanowski
Michal Trojanowski

Reputation: 12322

Your relation between the sfGuardUser and sfGuardUserProfile is not called Profile but SfGuardUserProfile. So you should use in your query builder:

 ->leftJoin('u.SfGuardUserProfile p')

Upvotes: 2

Related Questions