问题
I am trying to bind 3 models in cakephp.The relation is as follows
Member hasMany Member_Organaization Member_Organisations belongs to Organaization
i try to use
$this->Member->find('all',conditions)
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')));
I found this site to be very helpful. Thanks and Regards Himanshu Sharma
回答1:
Use recursive
the cakephp functionality for this type of purpose.
In your controller: $this->Member->recursive = 2;
use this before your find query.
Refrence : http://book.cakephp.org/view/1063/recursive
来源:https://stackoverflow.com/questions/7846230/binding-multiple-models-cakephp