Commit 8228c766 authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Issue #3077394 by ckaotik, sascha_meissner, Anybody: Sorting requires table alias to work

parent ed64a1b0
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -28,16 +28,16 @@ class OrderByDelta extends SortPluginBase {
    // want to add a order by to a table that does not exists, because if we do
    // that, a join will be created and we will fall in the same problem that
    // we are trying to solve here.
    $has_table = FALSE;
    $table_name = str_replace('__views_order_by_delta', '', $this->realField);
    $table_alias = NULL;
    $table_name = str_replace('__views_order_by_delta', '', $this->field);
    foreach ($this->query->tables as $table) {
      if (isset($table[$table_name])) {
        $has_table = TRUE;
        $table_alias = $table[$table_name]['alias'];
        break;
      }
    }
    if ($has_table) {
      $this->query->addOrderBy($table_name, 'delta', $this->options['order']);
    if ($table_alias) {
      $this->query->addOrderBy($table_alias, $this->realField, $this->options['order']);
    }
  }

+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ function views_order_by_delta_views_data() {
          'sort' => [
            'id' => 'order_by_delta',
          ],
          'real field' => 'delta',
        ];
       }
     }