在Doctrine中我可以:
$q = Doctrine_Query::create()
->from('One o')
->where('t.text = ?', 'aaa')
->andWhere('h.text = ?', 'bbb')
->leftJoin('o.Two t')
->leftJoin('t.Three h')
->leftJoin('h.Four f')
->execute();
我怎样才能在Symfony 1的Propel中做到这一点?
答案 0 :(得分:6)
如果你在1.6之前使用推进,你必须遵循
您必须知道每个关系的主键。
如果它是id
,它可能是这样的:
$c = new Criteria();
$c->add(TwoPeer::TEXT, 'aaa');
$c->add(ThreePeer::TEXT, 'bbb');
$c->addJoin(OnePeer::TWO_ID, TwoPeer::ID, Criteria::LEFT_JOIN);
$c->addJoin(TwoPeer::THREE_ID, ThreePeer::ID, Criteria::LEFT_JOIN);
$c->addJoin(ThreePeer::FOUR_ID, FourPeer::ID, Criteria::LEFT_JOIN);
$results = OnePeer::doSelect($c);
对于Propel 1.6 (从https://github.com/propelorm/sfPropelORMPlugin使用),类似的东西:
$results = OneQuery::create()
->useTwoQuery()
->filterByText('aaa')
->useThreeQuery()
->filterByText('bbb')
->endUse()
->endUse()
->leftJoinWith('Three.Four')
->find();
答案 1 :(得分:3)
关于j0k回答,更简单的方法是:
$results = OneQuery::create()
->useTwoQuery(null, Criteria::LEFT_JOIN)
->filterByText('aaa')
->useThreeQuery(null, Criteria::LEFT_JOIN)
->filterByText('bbb')
->endUse()
->endUse()
->find();