2014-12-03 131 views
0

如何添加第三个关系到我的关系()函数以加入CommentsPosts模型与store模型。 Where CommentsPosts.store_id = Store.id and CommentsPosts.store_zip = Store.zipYii不同模型之间的多重关系

我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

+0

当我想你可以添加在店面模式 – vijaykumar 2014-12-03 03:55:04

回答

0

我不确定你的关系,但尝试类似波纹管

在评论职位模型添加关系

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 
+0

店是一个不同的'模块/ model'比commentPost这种关系。这可以吗? – user2636556 2014-12-03 04:00:40

+0

尝试一次正确的关系。我认为这不是问题 – vijaykumar 2014-12-03 04:02:27

+0

嗯,在我看来。我添加了'print_r($ data-> store);'并且我得到了这个..'Property'Comment.store“没有被定义。' – user2636556 2014-12-03 04:07:36