Skip to content

Commit 3c7a44b

Browse files
committed
fixes
1 parent 5c30225 commit 3c7a44b

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/Models/Scopes/MappedColumnsScope.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,36 @@ private function mapColumns($array, $mappedColToDbColWithTable)
4040
}
4141

4242
foreach ($array as $key => $column) {
43-
$columnName = is_array($column) ? $column['column'] : $column;
43+
if (is_array($column)) {
44+
if ($column['type'] === 'Exists') {
45+
$column['query']->applyBeforeQueryCallbacks();
46+
47+
} elseif ($column['type'] === 'Column') {
48+
if ($newColumnName = $mappedColToDbColWithTable[$column['first']] ?? null) {
49+
$array[$key]['first'] = $newColumnName;
50+
}
51+
52+
if ($newColumnName = $mappedColToDbColWithTable[$column['second']] ?? null) {
53+
$array[$key]['second'] = $newColumnName;
54+
}
55+
56+
} elseif (isset($column['column'])) {
57+
if ($newColumnName = $mappedColToDbColWithTable[$column['column']] ?? null) {
58+
$array[$key]['column'] = $newColumnName;
59+
}
60+
}
61+
62+
// fixme: some unhandled cases?
4463
45-
if ($columnName === '*' || str_contains($columnName, ' as ')) { // todo: add support for column aliases
4664
continue;
4765
}
4866

49-
if ($newColumnName = $mappedColToDbColWithTable[$columnName] ?? null) {
50-
if (is_array($column)) {
51-
$array[$key]['column'] = $newColumnName;
52-
} else {
53-
$array[$key] = $newColumnName;
54-
}
67+
if ($column === '*' || str_contains($column, ' as ')) { // todo: add support for column aliases
68+
continue;
69+
}
70+
71+
if ($newColumnName = $mappedColToDbColWithTable[$column] ?? null) {
72+
$array[$key] = $newColumnName;
5573
}
5674
}
5775

0 commit comments

Comments
 (0)