绑定多个模型 Cakephp
我正在尝试在cakephp中绑定3个模型。关系如下
成员有很多 Member_Organizations Member_Organizations 属于 组织机构
我尝试使用的
$this->Member->find('all',conditions)
它只向我显示最多 hasMany 关联的数据。 据我了解,会员模型与组织模型没有直接关系。 但我们怎样才能做到呢? 我的代码如下:
$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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
recursive
cakephp 功能来实现此类目的。在您的控制器中:
$this->Member->recursive = 2;
在查找查询之前使用它。参考:
http://book.cakephp.org/view/1063/recursive
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