<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 中对多个表使用连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                Joomla include database functions(Joomla 包含数据库功能)
                nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)

                    • <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>