views:

31

answers:

2

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 ??

+1  A: 

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);
kpower
+1  A: 

If you declared this foreign key in your database schema, Propel will create extra functions for you that doe the join and hydration of the related tables and objects in one query:

$this->reunions = ReunionPeer::doSelectJoinLieu(new Criteria());
Jan Fabry