Jake Worrell
Jake Worrell

Reputation: 135

Propel - Joining the same table multiple times and grouping

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.

Upvotes: 1

Views: 2851

Answers (2)

dudow8
dudow8

Reputation: 19

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

Upvotes: 0

Mike Purcell
Mike Purcell

Reputation: 19999

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.

Upvotes: 1

Related Questions