Skip to content

Commit 227e0ee

Browse files
authored
Merge pull request #3236 from Seb33300/fix-column-alias
fix: improve column alias detection
2 parents f305033 + de14b63 commit 227e0ee

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/QueryDataTable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ protected function addTablePrefix($query, string $column): string
480480
// Column is an alias, no prefix required
481481
foreach ($q->columns ?? [] as $select) {
482482
$sql = trim($select instanceof Expression ? $select->getValue($this->getConnection()->getQueryGrammar()) : $select);
483-
if (str_ends_with($sql, ' as '.$column) || str_ends_with($sql, ' as '.$this->wrap($column))) {
483+
$match = preg_quote($column).'\b|'.preg_quote($this->wrap($column));
484+
if (preg_match("/(\s)as(\s+)($match)/i", $sql)) {
484485
return $column;
485486
}
486487
}

0 commit comments

Comments
 (0)