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

        <small id='v2JQj'></small><noframes id='v2JQj'>

          <bdo id='v2JQj'></bdo><ul id='v2JQj'></ul>
      2. Yii2 多对多关系的订单项

        Yii2 order items of many-to-many relation(Yii2 多对多关系的订单项)
              <tbody id='dpPtI'></tbody>
              1. <legend id='dpPtI'><style id='dpPtI'><dir id='dpPtI'><q id='dpPtI'></q></dir></style></legend>

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

                <small id='dpPtI'></small><noframes id='dpPtI'>

                  <bdo id='dpPtI'></bdo><ul id='dpPtI'></ul>
                  <tfoot id='dpPtI'></tfoot>
                  本文介绍了Yii2 多对多关系的订单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 2 个与连接 (slider_images) 表相关的表(滑块、图像),关系工作正常但我需要以特定顺序获取相关数据,定义正确顺序的属性在连接表中,关系定义为:

                  I've 2 tables (sliders, images) related with junction (sliders_images) table, the relation work fine but I nedd to get related data with specific order, the attribute that define the right order is in the junction table, the relation is defined as:

                  public function getImages(){
                      return $this->hasMany(Images::className(), ['id' => 'image_id'])
                          ->viaTable('sliders_images', ['slider_id' => 'id'], function($query){
                              $query->orderBy('sliders_images.display_order ASC');
                          });
                  }
                  

                  当我调用 $model->images 时,我收到了正确的图像但顺序错误,使用 foreach 图像是按 id 排序的,我如何才能获得按其他属性排序的图像?

                  when i call $model->images I receive the correct images but the wrong order, using foreach the images was ordered by id, how i can get the images ordered by other attribute?

                  推荐答案

                  正确的做法是添加join withjunction table ->joinWith('slidersImages') 获取joint table的属性然后按其中之一订购.完整代码:

                  The right way is to add a join with junction table ->joinWith('slidersImages') for get the junction table attributes and then order by one of those. The full code:

                  public function getImages(){
                          return $this->hasMany(Images::className(), ['id' => 'image_id'])
                          ->via('slidersImages')
                          ->joinWith('slidersImages SI')
                          ->orderBy('SI.display_order ASC');
                  }
                  

                  这篇关于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 中缓存)
                  1. <tfoot id='cCF7N'></tfoot><legend id='cCF7N'><style id='cCF7N'><dir id='cCF7N'><q id='cCF7N'></q></dir></style></legend>
                      <tbody id='cCF7N'></tbody>

                    <small id='cCF7N'></small><noframes id='cCF7N'>

                      <bdo id='cCF7N'></bdo><ul id='cCF7N'></ul>

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