嗨,我已经完成了 find() 并在一些结果中添加了一个新字段:
$approved = $this->ExpenseClaim->find('all', array('conditions'=> array('ExpenseClaim.claim_status_id' => '3')));
$i = 0;
foreach ($approved as $ap) {
$approved[$i]['ExpenseClaim']['claimTotal'] = $this->ExpenseClaim->expenseClaimTotal($approved[$i]['ExpenseClaim']['id']);
$i++;
}
我现在需要将它传递给分页,但是我在这里读到你不能这样做,我必须创建另一个模型才能仅在这个特定的查找上使用 afterFind() 方法。
所以我创建了名为的新模型ExpenseClaimTotal
并将 UseTable 设置为
public $useTable = 'expense_claims';
然后在新模型 afterFind() 方法中我做了一个简单的调试:
public function afterFind($results, $primary = false) {
debug($results);
//return $results;
}
但是,当我现在尝试在 pagesController 中针对这个新模型进行查找时,它失败了:
$this->loadModel('ExpenseClaimTotal');
$approved = $this->ExpenseClaimTotal->find('all', array('conditions'=> array('ExpenseClaim.claim_status_id' => '3')));
这是我得到的错误:
Database Error
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ExpenseClaim.claim_status_id' in 'where clause'
SQL Query: SELECT `ExpenseClaimTotal`.`id`, `ExpenseClaimTotal`.`user_id`, `ExpenseClaimTotal`.`claim_status_id`, `ExpenseClaimTotal`.`created`, `ExpenseClaimTotal`.`modified`, `ExpenseClaimTotal`.`approved`, `ExpenseClaimTotal`.`approved_by`, `ExpenseClaimTotal`.`declined_by`, `ExpenseClaimTotal`.`date_submitted` FROM `expenses`.`expense_claims` AS `ExpenseClaimTotal` WHERE `ExpenseClaim`.`claim_status_id` = 3
文档中似乎没有太多关于在一张桌子上使用 2 个模型