問(wèn)題描述
我試圖在cakephp中綁定3個(gè)模型,關(guān)系如下
I am trying to bind 3 models in cakephp.The relation is as follows
Member hasMany Member_Organization Member_Organisations 屬于組織
Member hasMany Member_Organaization Member_Organisations belongs to Organaization
我嘗試使用
$this->Member->find('all',conditions)
$this->Member->find('all',conditions)
它只向我顯示與 hasMany 關(guān)聯(lián)相關(guān)的數(shù)據(jù).我知道會(huì)員模型與組織模型沒(méi)有直接關(guān)系.但是我們?cè)撛趺醋瞿?我的代碼如下:
it just show me only data upto hasMany association. I understand that the Member model is not related directly to the organization one. but how can we do it? My code is as follows:
$this->Member->bindModel(
array(
'hasMany'=>array(
'NpoMember' =>array(
'className' => 'NpoMember',
'foreignKey' => 'member_id',
'conditions' => array('NpoMember.status' => 'Active'),
)
)
)
);
$this->NpoMember->bindModel(
array(
'belongsTo'=>array(
'Npo'=>array(
'className' => 'Npo',
'foreignKey' => 'npo_id',
'conditions' => array('Npo.status' => 'Active')
)
)
)
);
$userData = $this->Member->find('first',array('conditions'=>array('Member.email'=>$userEmail,'Member.password'=>$passWord,'Member.status'=>'Active')));
我發(fā)現(xiàn)這個(gè)網(wǎng)站非常有幫助.謝謝并恭祝安康喜滿樹(shù)夏爾馬
I found this site to be very helpful. Thanks and Regards Himanshu Sharma
推薦答案
使用 recursive
cakephp 功能來(lái)達(dá)到這種目的.
Use recursive
the cakephp functionality for this type of purpose.
在您的控制器中:$this->Member->recursive = 2;
在查找查詢之前使用它.
In your controller: $this->Member->recursive = 2;
use this before your find query.
參考:http://book.cakephp.org/view/1063/recursive
這篇關(guān)于綁定多個(gè)模型 Cakephp的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!