Skip to content

Commit bb24fa9

Browse files
committed
support query alias for the mapped attribute
1 parent b8786eb commit bb24fa9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Mappable.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function mappedSelect(Builder $query, ArgumentBag $args)
8989
$columns = $args->get('columns');
9090

9191
foreach ($columns as $key => $column) {
92-
list($column) = $this->extractColumnAlias($column);
92+
list($column, $as) = $this->extractColumnAlias($column);
9393

9494
// Each mapped column will be selected appropriately. If it's alias
9595
// then prefix it with current table and use original field name
@@ -107,6 +107,10 @@ protected function mappedSelect(Builder $query, ArgumentBag $args)
107107

108108
$columns[$key] = "{$table}.{$mapped}";
109109

110+
if ($as !== $mapped) {
111+
$columns[$key] .= " as {$as}";
112+
}
113+
110114
// For non mapped columns present on this table we will simply
111115
// add the prefix, in order to avoid any column collisions,
112116
// that are likely to happen when we are joining tables.

0 commit comments

Comments
 (0)