PMCORE-1882 Suggest Field doesn't show records when we use an alias in a Query

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-08-21 00:44:20 -04:00
parent 9d3b85724a
commit bd09154369
3 changed files with 82 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
<?php
use PhpMyAdmin\SqlParser\Parser;
use ProcessMaker\Core\System;
use ProcessMaker\BusinessModel\DynaForm\SuggestTrait;
use ProcessMaker\BusinessModel\Cases;
@@ -1044,6 +1045,16 @@ class PmDynaform
$dt[$key]["alias"] = "";
}
if ($key == 0) {
//compatibility with table name alias when uses the sentence 'AS'
if (strtoupper($dt[$key]["alias"]) === 'AS') {
$parser = new Parser($sql);
if (isset($parser->statements[$key]) && isset($parser->statements[$key]->from[$key])) {
$obj1 = $parser->statements[$key]->from[$key];
if (!empty($obj1->alias)) {
$dt[$key]["alias"] = $dt[$key]["alias"] . ' ' . $obj1->alias;
}
}
}
$from .= $dt[$key]["table"]
. ($dt[$key]["table"] == $dt[$key]["alias"] ? "" : " " . $dt[$key]["alias"]);
} else {