<legend id='4n0LB'><style id='4n0LB'><dir id='4n0LB'><q id='4n0LB'></q></dir></style></legend>

<small id='4n0LB'></small><noframes id='4n0LB'>

  1. <i id='4n0LB'><tr id='4n0LB'><dt id='4n0LB'><q id='4n0LB'><span id='4n0LB'><b id='4n0LB'><form id='4n0LB'><ins id='4n0LB'></ins><ul id='4n0LB'></ul><sub id='4n0LB'></sub></form><legend id='4n0LB'></legend><bdo id='4n0LB'><pre id='4n0LB'><center id='4n0LB'></center></pre></bdo></b><th id='4n0LB'></th></span></q></dt></tr></i><div id='4n0LB'><tfoot id='4n0LB'></tfoot><dl id='4n0LB'><fieldset id='4n0LB'></fieldset></dl></div>
    1. <tfoot id='4n0LB'></tfoot>
        <bdo id='4n0LB'></bdo><ul id='4n0LB'></ul>

      在 yii2 中对多个表使用连接

      use Joins for multiple tables in yii2(在 yii2 中对多个表使用连接)
          <tbody id='4AAp6'></tbody>
        <tfoot id='4AAp6'></tfoot>
        <legend id='4AAp6'><style id='4AAp6'><dir id='4AAp6'><q id='4AAp6'></q></dir></style></legend>
        1. <small id='4AAp6'></small><noframes id='4AAp6'>

        2. <i id='4AAp6'><tr id='4AAp6'><dt id='4AAp6'><q id='4AAp6'><span id='4AAp6'><b id='4AAp6'><form id='4AAp6'><ins id='4AAp6'></ins><ul id='4AAp6'></ul><sub id='4AAp6'></sub></form><legend id='4AAp6'></legend><bdo id='4AAp6'><pre id='4AAp6'><center id='4AAp6'></center></pre></bdo></b><th id='4AAp6'></th></span></q></dt></tr></i><div id='4AAp6'><tfoot id='4AAp6'></tfoot><dl id='4AAp6'><fieldset id='4AAp6'></fieldset></dl></div>

                <bdo id='4AAp6'></bdo><ul id='4AAp6'></ul>
                本文介绍了在 yii2 中对多个表使用连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 yii2,我有 3 个表:帖子、粉丝、评论,我想使用 joinWith() 获取带有他们评论的帖子以及帖子和评论的粉丝名称(在粉丝表中).我写的是这个查询:

                facebook_posts::find()->joinwith('fans')->joinWith('comments')->all();

                并且我为关系添加了这两个函数:

                公共函数 getfans() {return $this->hasOne(Fans::className(), ['id' => 'from_id'])->from(fans::tableName() . 'FBF');}公共函数 getComments() {return $this->hasMany(Comments::className(), ['parent_id' => 'id'])->from(comments::tableName() .'FBC');}

                这给了我写帖子的粉丝的帖子和数据及其评论,但我需要的是也写评论的粉丝的数据,那么我如何将评论加入粉丝表??

                解决方案

                确保您的 Comments 模型中有 fan 关系,然后您可以使用以下内容获取每个帖子的所有评论以及每个评论的粉丝关系:

                facebook_posts::find()->joinWith('fans')->joinWith(['comments', 'comments.fan'])->all();

                I am using yii2, I have 3 tables: posts, fans, comments and i want to use joinWith() to get the posts with their comments and the fan name (in fans table) for post and comments. what i wrote is this query:

                <pre>
                 facebook_posts::find()->joinwith('fans')->joinWith('comments')->all();
                </pre>
                

                and I added these two functions for the relations:

                <pre>
                    public function getfans() {
                        return $this->hasOne(Fans::className(), ['id' => 'from_id'])->from(fans::tableName() . ' FBF');
                    }
                    public function getComments() {
                        return $this->hasMany(Comments::className(), ['parent_id' => 'id'])->from(comments::tableName() . ' FBC');
                    }
                </pre>
                

                this gives me the posts and the data of the fan who wrote the post and its comments but what i need is the data of fan that wrote the comments also, so how can i join comments with fans table ??

                解决方案

                Make sure you have a fan relation in your Comments model, then you can use the following to get all comments for each post and the fan relation for each comment:

                facebook_posts::find()->joinWith('fans')->joinWith(['comments', 'comments.fan'])->all();
                

                这篇关于在 yii2 中对多个表使用连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    • <tfoot id='EKxYR'></tfoot>
                    • <small id='EKxYR'></small><noframes id='EKxYR'>

                        <tbody id='EKxYR'></tbody>
                        <legend id='EKxYR'><style id='EKxYR'><dir id='EKxYR'><q id='EKxYR'></q></dir></style></legend>
                        <i id='EKxYR'><tr id='EKxYR'><dt id='EKxYR'><q id='EKxYR'><span id='EKxYR'><b id='EKxYR'><form id='EKxYR'><ins id='EKxYR'></ins><ul id='EKxYR'></ul><sub id='EKxYR'></sub></form><legend id='EKxYR'></legend><bdo id='EKxYR'><pre id='EKxYR'><center id='EKxYR'></center></pre></bdo></b><th id='EKxYR'></th></span></q></dt></tr></i><div id='EKxYR'><tfoot id='EKxYR'></tfoot><dl id='EKxYR'><fieldset id='EKxYR'></fieldset></dl></div>
                          <bdo id='EKxYR'></bdo><ul id='EKxYR'></ul>