Search code examples
symfony1criteriapropel

How to do a join with ttwo tables?


HI,

I try to translate this query :

SELECT *
FROM `reunion` , lieu
WHERE reunion.lieu_reunion = lieu.id_lieu

to propel query :

$c=new Criteria();
$c->addJoin(ReunionPeer::LIEU_REUNION,LieuPeer::ID_LIEU, Criteria::LEFT_JOIN);
$this->reunions = ReunionPeer::doSelect($c);

But in my template, when I made a print_r($reunions), the field "ville" (from the table 'lieu') is not present.

Why ??


Solution

  • First of all, your propel query will be transformed to:

    SELECT * FROM `reunion` LEFT JOIN lieu ON (reunion.lieu_reunion = lieu.id_lieu);
    

    Then I can suggest this:

    $c=new Criteria();
    $c->clearSelectColumns();
    ReunionPeer::addSelectColumns($c);
    LieuPeer::addSelectColumns($c);
    
    $c->addJoin(ReunionPeer::LIEU_REUNION,LieuPeer::ID_LIEU, Criteria::LEFT_JOIN);
    $this->reunions = ReunionPeer::doSelect($c);