使用Doctrine_RawSql对象加入3个表

时间:2011-03-03 14:06:14

标签: php mysql join doctrine

有没有办法让这个选择:

SELECT * 
FROM `sf_guard_user` 
JOIN `friendship` 
  ON `friendship`.`user_id` = `sf_guard_user`.`id` 
JOIN `circle` 
  ON `friendship`.`circle_id` = `circle`.`id` 
WHERE `circle`.`id` = 1 
ORDER BY `circle`.`id`

使用Doctrine_RawSql对象而不使用外键?

1 个答案:

答案 0 :(得分:1)

你为什么决定使用Doctrine_RawSql?

在此示例中,我使用的是inner join

SELECT sf.* FROM `sf_guard_user` sf
INNER JOIN `friendship` f on  f.`user_id` = sf.`id` 
INNER JOIN `circle` c on f.`circle_id` = c.`id` 
WHERE c.`id` = 1 
ORDER BY c.`id`