Propel and leftJoin

自作多情 提交于 2019-12-12 12:08:36

问题


In 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 make this in Propel from Symfony 1?


回答1:


If you use propel before 1.6, you have to follow

You have to know the primary key for each relation. If it's id, it can be something like that:

$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 from https://github.com/propelorm/sfPropelORMPlugin), something like that:

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



回答2:


In relation to j0k answer, an easier way would be:

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


来源:https://stackoverflow.com/questions/9735666/propel-and-leftjoin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!