Reputation: 127
There are users:
id | name
1 user1
2 testuser
There are tasks:
id | creatorid | ownerid| name
1 1 1 task1
2 1 2 task2
3 2 1 task3
4 2 2 task4
I did something like that:
Doctrine_Core::getTable('User')->createQuery()->leftJoin('User.Task')
but then the tables are connected with "creatorid", and not "ownerid", how to specify it?
Upvotes: 1
Views: 4500
Reputation: 12352
It depends on how you define the Task
relation on the Users
table. You should have something like:
Tasks:
...
relations:
owner: {class: User, local: ownerId, foreign: id, foreignAlias: ownedTasks}
creator: {class: User, local: creatorId, foreign: id, foreignAlias: createdTasks}
Then you can use:
Doctrine_Core::getTable('User')->createQuery()->leftJoin('User.ownedTasks)
to join by the owners or
Doctrine_Core::getTable('User')->createQuery()->leftJoin('User.createdTasks')
to join by the creator.
Upvotes: 1
Reputation: 189
I use Doctrine_Query
$q = Doctrine_Query::create()
->select('u.*, t.*')
->from('Users u')
->leftJoin('u.Tasks t ON u.id = t.creatorid');
echo $q->getSqlQuery();
Doctrine 1.2 Left Join Documentation
Upvotes: 2