Commit 17bd7b3f authored by Christian López Espínola's avatar Christian López Espínola Committed by Andrii Podanenko
Browse files

Issue #3254174 by penyaskito, iStryker: Use COALESCE instead of ISNULL for...

Issue #3254174 by penyaskito, iStryker: Use COALESCE instead of ISNULL for ensuring compatibility with postgres
parent 2cd2a371
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -115,12 +115,11 @@ class DraggableViewsSort extends SortPluginBase {

    $this->alias = $this->query->addRelationship($alias, $join, $this->query->view->storage->get('base_table'), $this->relationship);

    if ($this->options['draggable_views_null_order'] == "before") {
      $formula = "!ISNULL($this->alias.$this->realField)";
    }
    else {
      $formula = "ISNULL($this->alias.$this->realField)";
    }
    // We cannot use ISNULL() for compatibility with postgres, so use coalesce
    // function instead. We use the mix or max php integer as default value based
    // on if we want those with null before or after.
    $coalesce_null_value = $this->options['draggable_views_null_order'] == "before" ? PHP_INT_MIN : PHP_INT_MAX;
    $formula = "COALESCE($this->alias.$this->realField, $coalesce_null_value)";

    // We add both to handle ordering of NULL values.
    $this->query->addOrderBy(NULL, $formula, $this->options['order'], $this->alias . "_" . $this->realField);