【发布时间】:2012-02-03 21:41:40
【问题描述】:
FIRST:
id | name
1 | sss
2 | ddd
5 | fff
$q = Doctrine_Query::create()
->from('First a');
return $q->execute();
SECOND:
id | first_id | name
....
$two = Doctrine_Query::create()
->from('Second a')
->whereInNot(first_id, $q) // ???????
;
return $two->execute();
如果表 FIRST 中不存在 first_id,如何从表 SECOND 中获取所有数据?
【问题讨论】:
-
您的代码的问题包括:第一个查询返回一个 Doctrine_Collection(如 Doctrine_Records 列表),它不是您可以输入第二个查询的数组。此外,您需要的方法是“whereNotIn()”而不是“whereInNot()”。我在回答中提供了两个示例,说明如何编写代码,具体取决于您是否真的需要知道 first_ids。
标签: php sql symfony1 doctrine symfony-1.4