Binding multiple models Cakephp

陌路散爱 提交于 2019-12-19 11:28:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!