• <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 多对多关系的订单项

        时间:2023-10-16
              <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 多对多关系的订单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将具有相同索引和值的 2 个数组与 php 组合? 下一篇:使用 php yii2 在 Chrome 中下载 Excel 文件失败

                  相关文章

                  1. <tfoot id='cCF7N'></tfoot><legend id='cCF7N'><style id='cCF7N'><dir id='cCF7N'><q id='cCF7N'></q></dir></style></legend>
                  2. <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>