我找不到关于cakephp的可链接行为的任何好文档。我正在尝试使用它,我已经在互联网上找到了一些代码示例,但是我得到了一个SQL错误,并且它返回298行应该是136,因为它显示的是没有记录Rental模型中指定的表中的相关记录。我想代码:array('not'=> array('Rental.ri_num'=> null)会阻止那些行显示。所以,我需要知道哪里有好文档,为什么我'我收到了错误列表。如果我可以使用此查询查看所有超过5和少于15个租赁的代理商。或类似的。
-------------------------------------------------------------------------
ERRORS
----------------------------------------------------------------------------
Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bind' at line 1 [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
Query: bind
Notice (8): Undefined index: ReferralCommission [APP\models\behaviors\linkable.php, line 83]
-------------------------------------------------------------------------
CODE
----------------------------------------------------------------------------
<?php
class ReferralCommissionsController extends AppController {
var $helpers = array ('Html', 'Form', 'Ajax');
var $name = 'ReferralCommissions';
var $uses = array('ReferralCommission', 'Referral', 'Rental', 'RentalLineitem', 'Agent');
var $components = array('RequestHandler');
function unpaid() {
$this->layout = 'ajax';
$unpaidcommissions = $this->ReferralCommission->find('all',
array(
'link' => array('Rental' => array( 'RentalLineitem')),
'conditions' => array( array('not' => array('Rental.ri_num' => null)),
'RentalLineitem.ri_bill_e_dte <' => time(),
'ReferralCommission.rc_amt_paid' => '0'),
'contain' => array('Agent', 'Rental')
));
foreach ($unpaidcommissions as &$unpaidcomm) {
$agencyid = $unpaidcomm['ReferralCommission']['r_num'];
}
$this->set('unpaidcount', count($unpaidcommissions));
$this->set('commissions', $unpaidcommissions);
}
}
?>
答案 0 :(得分:0)
我已经找出了这个错误的原因,并且从那以后已经多次得到它。每次我得到一个错误,其中查询只是“绑定”,它一直是造成这种情况的关系。在这种情况下,需要正确设置$ belongsTo和$ hasMany关系。如果其他人得到这样的错误,请检查被引用的两个模型,并确保关系确实正确设置。