【发布时间】:2015-02-02 11:45:48
【问题描述】:
控制器
public function index(){
$this->Store->unbindModel(
array('belongsTo' => array('Employee')), true
);
$options=array(
'joins' =>
array(
array(
'table' => 'Employee',
'alias' => 'Employee',
'foreignKey' => true,
'conditions'=> array('Employee.employee_store = Store.store_name')
)
));
$coupons = $this->Store->find('all', $options);
}
型号
类商店扩展 AppModel { var $useTable = '商店'; }
Sql:
SELECT `Store`.`id`,
`Store`.`store_name`,
`Store`.`store_address`,
`Store`.`store_phone`,
`Store`.`store_email`,
`Store`.`store_website`,
`Store`.`date_enter`,
`Store`.`store_shortcode`
FROM `billing`.`store` AS `Store`
JOIN `billing`.`Employee` AS `Employee` ON (`Employee`.`employee_store` = `Store`.`store_name`)
WHERE 1 = 1
我需要同时显示 Employee 和 Store 表列。 (员工表中的employee_name、employee_mail 等,商店表中的Store_name、store_add)
【问题讨论】:
标签: cakephp cakephp-2.0 cakephp-1.3 cakephp-2.1 cakephp-2.3