问题
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