[英]Yii multiple relations between different models in different modules
我如何在我的Relations()函数中添加第3个关系以将CommentsPosts
模型与store
模型结合在一起。 其中CommentsPosts.store_id = Store.id
和CommentsPosts.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.