[英]join 3 tables on cakephp
I'm trying to join 3 tables using cakephp but I don't understand why when I execute my query there is the result of the main tables without the attributes from the other 2 tables . 我试图使用cakephp联接3个表,但是我不明白为什么当我执行查询时,主表的结果没有其他2个表的属性。 this is my php code :
这是我的PHP代码:
$flightSchedule = $this->FlightSchedules->find('all', array(
'join' => array(
array(
'table' => 'WeeklySchedules',
'alias' => 'ws',
'type' => 'INNER',
'conditions' => array(
'FlightSchedules.code = ws.flight_plan_code'
),
array(
'table' => 'Structures',
'alias' => 's',
'type' => 'LEFT',
'conditions' => array(
'FlightSchedules.code = s.flight_plan_code',
)),
)),
'conditions' => array(
'FlightSchedules.plane_code' => 'xxx'
),
));
the result of this is always the FlightSchedules record without the join of the other tables . 其结果始终是FlightSchedules记录,而没有其他表的联接。 Any ideas how to fix this ?
任何想法如何解决这一问题 ?
use "fields" for display the data of an associated table . 使用“字段”显示关联表的数据。
$flightSchedule = $this->FlightSchedules->find('all', array(
'join' => array(
array(
'table' => 'WeeklySchedules',
'alias' => 'ws',
'type' => 'INNER',
'conditions' => array(
'FlightSchedules.code = ws.flight_plan_code'
),
array(
'table' => 'Structures',
'alias' => 's',
'type' => 'LEFT',
'conditions' => array(
'FlightSchedules.code = s.flight_plan_code',
)),
)),
'conditions' => array(
'FlightSchedules.plane_code' => 'xxx'
),
'fields'=>'FlightSchedules.*,ws.*,s.*'
));
在condition array
之后添加
'fields' => 'FlightSchedules.*, WeeklySchedules.*, Structures.*'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.