开发者

How to do a join with ttwo tables?

开发者 https://www.devze.com 2023-01-01 20:38 出处:网络
HI, I try to translate this query : SELECT * FROM `reunion` , lieu WHERE reunion.lieu_reunion = lieu.id_lieu

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开发者_JAVA百科($reunions), the field "ville" (from the table 'lieu') is not present.

Why ??


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);


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());
0

精彩评论

暂无评论...
验证码 换一张
取 消