【发布时间】:2014-04-30 11:26:11
【问题描述】:
我有两张桌子employees 和posting。
employees 带有字段id,name
与
postings 字段为id,employee_id,status
现在检索我在PostingsController.php 的view() 操作中写的Posting.status = 1 的所有员工(带有发布详细信息):
$cond = array('Posting.status'=>1);
$e = $this->Employee->find('all',array('conditions' => $cond));
$this->set('emp',$e);
在Employee.php 模型var $hasMany = 'Posting';
在Posting.php 模型var $belongsTo = 'Employee';
但是上面的代码会产生如下错误:
错误:SQLSTATE[42S22]:找不到列:1054 未知列 'where 子句'中的'Posting.status'
生成的 SQL:
SQL Query: SELECT `Employee`.`id`, `Employee`.`name` FROM `cakelab`.`employees` AS `Employee` WHERE `Posting`.`status` = 1
我是 CakePhp 的新手,请指导我。
【问题讨论】:
-
请发布产生该错误的 SQL 查询
-
@arilia 查看我更新的问题
-
两个可能的原因(我能想到的): 1. 模型中有一些输入错误(在
hasMany或belongsTo中)。 2. 您的recursive选项在某处设置为-1。请复制粘贴模型的相关部分。另外,您提到您是 cake 连接的新手,如果不专门使用它对用户是透明的 - 您是否已经逐渐变细了?
标签: sql cakephp join conditional-statements