确定。这对你来说一定很容易就是那个蛋糕忍者!但我的cakePHP技能仍处于最低水平。所以我有2个型号;捐赠者模型和捐赠模型。
设置如下:
捐赠者模型有许多捐赠模式
捐赠者模型
public $hasMany = array(
'Donation' => array(
'className' => 'Donation',
'foreignKey' => 'donor_id',
'order' => 'Donation.created DESC',
'limit' => 10,
'dependent' => true
)
);
现在在DonorsController中,我正在使用paginatorComponent的paginate()方法。在我的索引中,我有这个代码
public function index($id = null){
$options['joins'] = array(
array(
'table' => 'donations',
'alias' => 'Donation',
'type' => 'LEFT',
'conditions' => array(
'Donor.id = Donation.donor_id',
))
);
$donors = $this->Paginator->paginate('Donor',$options);
$this->set('donors',$donors);
}
但是这会返回一个sql错误: '1054未知列'加入'where子句'''
任何人都知道为什么会发生这种情况,或者上述代码是否正确?感谢
答案 0 :(得分:1)
您的代码不正确,请参阅以下功能:
public function index($id = null){
$options['joins'] = array(
array(
'table' => 'donations',
'alias' => 'Donation',
'type' => 'LEFT',
'conditions' => array(
'Donor.id = Donation.donor_id',
))
);
$this->paginate = $options;
$donors = $this->Paginator->paginate('Donor');
$this->set('donors',$donors);
}