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


Yii multiple relations between different models in different modules

我将如何向我的 relations() 函数添加第 3 个关系以将CommentsPosts模型与store模型连接起来。CommentsPosts.store_id = Store.idCommentsPosts.store_zip = Store.zip在哪里?

在我的评论中.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'=>'',
            );
        }

评论帖子.php在modules/comments/model和商店.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