绑定多个模型 Cakephp

发布于 2024-12-11 13:03:15 字数 1327 浏览 0 评论 0原文

我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2024-12-18 13:03:15

使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文