Propel - Joining the same table multiple times and grouping

寵の児 提交于 2019-12-13 20:01:46

问题


I'm writing a report with Propel and need to join the same table multiple times in order to get different stats for different date ranges using the same data.

The issue appears to be that propel ignores multiple ->leftJoin() calls on a query. I think I need to alias each join so they can be treated individually but I can't find a way to do that.


回答1:


Try addJoin()

$c = new Criteria();
$c->addJoin(array(Table1Peer::ID,), array(Table2Peer::Table1Peer_ID,), Criteria::LEFT_JOIN);

Looks like you can also alias:

$c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);

With the ability to alias and pass in arrays it seems you should be able to do multi-joins to the same table.




回答2:


Or, you can just add "RelatedBy" relationship methods ...

Ex.:

ItemQuery::create()
->leftJoinItemRelatedByCodItemFather( 'Child' )
    ->addAsColumn( 'ChildName', "Child.name" )
->find() ;

I Always prefer to use auto generated Propel Methods =D



来源:https://stackoverflow.com/questions/7969926/propel-joining-the-same-table-multiple-times-and-grouping

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