从yii2中的表获取数据的问题
我已经在YII2模型用户中创建了方法,以获取当前用户
public函数getallRepliesForusers(){return $ this-> hasmany的 所有答复]) - > viatable('requeies_links',['requeies_id'=> 'id'])) - >其中(['entity'=>'用户']); }
我的回复表 我的用户表
和链接这两个表
我的方法正确吗?
I have created method in the Yii2 model Users to get all the replies for the current user
public function getAllRepliesForUsers() { return $this->hasMany(Replies::class, ['user_id' => 'id'])->viaTable('replies_links', ['replies_id' => 'id'])->where(['entity'=>'user']); }
My replies table
My users table
and the final table that links these two tables
Is my method is correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是用户与答复的关系。您可以使用GII模块的型号生成器,这样您就不会通过手动键入它们而感到困惑。
(我可以知道您打算如何处理条件 - >在哪里(['entity'=>'user'])?)。
Here's the relationship of Users to the Replies. You can use the Model generator of Gii module so you won't get confused by manually typing them.
(May I know what do you intend to do with the condition ->where(['entity'=>'user'])?).