SUBSCRIBE VIA RSS


Subscribe to our feed

Status Updates

  • First iPhone app nearly complete! I've been waiting for 3 weeks for Apple to finish "conducting company identity verification."
    3 days ago
  • Rainy day! Staying indoors. Creating computerized players in a simulation game that models cooperation in the work place.
    75 days ago
  • Up at 8AM, with a hot cup of coffee brought back from Cafe Lola in Ann Arbor. Will I succeed in putting in 8 billable hours in one day?
    100 days ago
  • full scale irish band outside my window playing the pipes for the past 20 minutes. pretty fun.
    109 days ago
  • listening to Kristin on Maxim Radio!
    115 days ago
  • back from an amazing meal at ouest with even more amazing company.
    115 days ago
  • wondering how so many online tshirt companies stay in business--ones that sell shirts with funny messages, i never see them in real life
    122 days ago

Topics

TWITTER

The old fashioned way

RECENT TUNES

January 24, 2008 – 4:48pm Propel Criteria Left Join: using addJoin() and addAlias() to join a table twice

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!

Posted in  Web Development   |     |  delicious  Digg

4 Responses to “Propel Criteria Left Join: using addJoin() and addAlias() to join a table twice”

  1. 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

  2. Thanks,

    This brings me again a little closer to my first demo!

    By Leon on Jul 1, 2008

2 Trackback(s)

  1. Jan 27, 2008: rpsblog.com » A week of symfony #56 (21->27 January 2008)
  2. Feb 3, 2008: Symfony.es » Blog Archive » Una semana con Symfony #29 (21->27 enero 2008)

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word