推进ORM:选择“不在”状态的标准

时间:2014-05-08 15:21:52

标签: mysql orm symfony-1.4 propel

如何为此类查询构建推进标准:

SELECT * FROM Table1 WHERE id not in (SELECT id FROM Table2 WHERE field1 = 2)

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,可以使用Criteria::CUSTOM,例如:

public static function getElementsWithNotIn(){
    $c = new Criteria();
    $c->add(Table1Peer::ID, Table1Peer::ID . ' NOT IN (SELECT '. Table2Peer::ID .' FROM '. Table2Peer::TABLE_NAME .')', Criteria::CUSTOM);
    return Table1Peer::doSelect($c);
}