请帮我在Cakephp中解决这个问题,
我有两个名为employees
和fees
的表。
Th employees
表仅用于员工详细信息和
fees
表用于存储员工每月的附加费用条目。
我希望从employees
表中获取所有未在fees
表格中输入特定月费的员工。
简单地说,获取所有未支付选定月份费用的在职员工。
请帮我在cakephp中解决这个问题
表结构如下所列
员工
+--------------+------------+----------+
| EmployeeId | name | active |
+--------------+------------+----------+
| 6 | Mike | 1 |
| 7 | Ethen | 0 |
| 9 | Sony | 1 |
+--------------+------------+----------+
费
+--------+-------------+-------------+
| FeeId | EmployeeId | monthYear |
+--------+-------------+-------------+
| 1 | 6 | 2015-09 |
| 4 | 7 | 2015-09 |
| 6 | 6 | 2015-08 |
+--------+-------------+-------------+
我试过这个
$searchFromDate = date('Y-m',strtotime($this->data['searchFromDate']));
$this->Paginator->settings = array('fields'=>array('Employee.name'),
'joins'=>array(
array(
'alias'=>'Fee',
'table'=>'fees',
'conditions' =>array('Fee.monthYear = '.$searchFromDate)
)
),
'conditions' => array(
'NOT' => array(
'Employee.EmployeeId' => 'Fee.EmployeeId'
)),
'order' => array('Employee.name' => 'ASC') );
$resultData = $this->Paginator->paginate('Employee');
答案 0 :(得分:0)
将您的查找条件更改为:
'joins'=>array(
array(
'alias'=>'Fee',
'table'=>'fees',
'conditions' =>array(
'Fee.monthYear = $searchFromDate',
'Employee.EmployeeId = Fee.EmployeeId'
)
)
),
'conditions' => array(
'Fee.FeeId' => null
)),