我有三张桌子:
Project:
...
relations:
User:
local: authorId
foreign: id
Users:
class: User
local: projectId
foreign: userId
refClass: UserProjects
User:
...
relations:
Projects:
class: Project
local: userId
foreign: projectId
refClass: UserProjects
UserProjects:
columns:
id:
type: integer
primary: true
autoincrement: true
userId: integer
projectId: integer
我想做的是编写一个 DQL 语句来返回用户关联的项目。我正在尝试模仿以下内容:
SELECT p.*
FROM user_projects AS up
LEFT JOIN project AS p ON up.projectid = p.id
LEFT JOIN user AS u ON up.userid = u.id
WHERE u.id = 1
通读 Doctrine 指令,我想到了以下内容(u.* 在那里,因为它抱怨 u 没有在 select 语句中使用):
$q = Doctrine_Query::create()
->from('Model_User u')
->select('u.*, p.*')
->leftJoin('u.Projects p');
$result = $q->execute();
但它返回的是一个包含单个 Model_User 对象的数据集,该对象具有填充了相关项目的“项目”属性。如果可能的话,我只想让项目返回,但我似乎无法弄清楚。可能吗?