add join 에 조건이 두개 있을때
2010. 3. 18. 11:07ㆍ99. 정리전 - IT/17. Symfony 퉷퉷
Criteriaを利用して例えばこんなSQLを組み立てたい場合
SELECT *
FROM table1 a
LEFT JOIN table2 b ON a.column1 = b.column1 AND a.column2 = b.column2
FROM table1 a
LEFT JOIN table2 b ON a.column1 = b.column1 AND a.column2 = b.column2
普通にaddJoinを使っても条件をひとつつしか指定できません。
$c = new Criteria();
$c->addJoin(Table1Peer::COLUMN1, Table2Peer::COLUMN1, Criteria::LEFT_JOIN);
$c->addJoin(Table1Peer::COLUMN1, Table2Peer::COLUMN1, Criteria::LEFT_JOIN);
少し強引ですが、こういう書き方ができるようです。
$c = new Criteria();
$c->addJoin(Table1Peer::COLUMN1, Table2Peer::COLUMN1 .
' AND ' . Table1Peer::COLUMN2 . ' = ' . Table2Peer::COLUMN2, Criteria::LEFT_JOIN);
// LEFT JOIN table2 b ON a.column1 = b.column1 AND a.column2 = b.column2
$c->addJoin(Table1Peer::COLUMN1, Table2Peer::COLUMN1 .
' AND ' . Table1Peer::COLUMN2 . ' = ' . Table2Peer::COLUMN2, Criteria::LEFT_JOIN);
// LEFT JOIN table2 b ON a.column1 = b.column1 AND a.column2 = b.column2