Here is a way to do left join on two columns in a table that both were foreign keys in the same table using Propel. This might happen if for example you have a table with a parent_id and a child_id in a nested set that both refer to the same table, or as an example you have a table “documentation” and each documentation can be categorized into a main category and a sub category.
What happens when you want to do a left join in your documentation query, so that if present both the related category and sub_category objects get included in the results?
$c->addJoin(DocumentationPeer::CATEGORY, CategoryPeer::ID, Criteria::LEFT_JOIN); $c->addJoin(DocumentationPeer::SUB_CATEGORY, CategoryPeer::alias('c2', CategoryPeer::ID), Criteria::LEFT_JOIN); $c->addAlias('c2', CategoryPeer::TABLE_NAME);
Done and done!



hi
by any hasard, did you find a way to join the same table twice using the same foreign key? that may seems strange but there are case where that could be usefull, for example in nested set implementations (retrieving category breadcrumb) or in many to many relation (A)-(B) in chich you want to retrieve every records A which are related to same B records than a model A.
I tryed hard to find a way to do this but I had no chance… Hope you can enlighten me on this
Hartym
By hartym on Jan 28, 2008
Thanks,
This brings me again a little closer to my first demo!
By Leon on Jul 1, 2008