Propel and leftJoin

In the Doctrine, I can:

$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(); 

How can I do this in Propel from Symfony 1?

+4
source share
2 answers

If you use propel prior to 1.6 , you must follow

You must know the primary key for each relationship. If it's id , it could be something like this:

 $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); 

For Propel 1.6 (use it https://github.com/propelorm/sfPropelORMPlugin ), something like this:

 $results = OneQuery::create() ->useTwoQuery() ->filterByText('aaa') ->useThreeQuery() ->filterByText('bbb') ->endUse() ->endUse() ->leftJoinWith('Three.Four') ->find(); 
+6
source

In response to j0k, the answer will be simpler:

 $results = OneQuery::create() ->useTwoQuery(null, Criteria::LEFT_JOIN) ->filterByText('aaa') ->useThreeQuery(null, Criteria::LEFT_JOIN) ->filterByText('bbb') ->endUse() ->endUse() ->find(); 
+3
source

Source: https://habr.com/ru/post/1401787/


All Articles