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

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

                  相关文档推荐

                  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 的问题)
                  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>