繁体   English   中英

不同模块中不同模型之间的Yii多重关系

[英]Yii multiple relations between different models in different modules

我如何在我的Relations()函数中添加第3个关系以将CommentsPosts模型与store模型结合在一起。 其中CommentsPosts.store_id = Store.idCommentsPosts.store_zip = Store.zip吗?

在我的comment.php中

  public function relations()
        {
            return array(
                'user' => array(self::BELONGS_TO, $this->module->userModelClass, 'userId'),
                'posts' => array(self::HAS_MANY, "CommentsPosts", array("commentId" => "id")),
                'store'=>'',

            );
        }

CommentsPost.php位于modules/comments/model而Store.php位于modules/store/model

仅供参考,我使用的是Yii 1.1.15

我不确定您的关系,但可以尝试以下方法

在评论发布模型中添加关系

 public function relations()
        {
            return array(

                'store' => array(self::HAS_MANY, "Store", array("store_id" => "id")),


            );
        }

检索时

   $enity->post // give all post 
   $enity->post[i]->store // gives the each post data of store

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM