Propel - Joining the same table multiple times and

2019-08-04 11:14发布

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.

2条回答
甜甜的少女心
2楼-- · 2019-08-04 11:26

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

查看更多
啃猪蹄的小仙女
3楼-- · 2019-08-04 11:28

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.

查看更多
登录 后发表回答