Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Blazik committed Oct 29, 2023
1 parent 5c30225 commit 3c7a44b
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/Models/Scopes/MappedColumnsScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,36 @@ private function mapColumns($array, $mappedColToDbColWithTable)
}

foreach ($array as $key => $column) {
$columnName = is_array($column) ? $column['column'] : $column;
if (is_array($column)) {
if ($column['type'] === 'Exists') {
$column['query']->applyBeforeQueryCallbacks();

} elseif ($column['type'] === 'Column') {
if ($newColumnName = $mappedColToDbColWithTable[$column['first']] ?? null) {
$array[$key]['first'] = $newColumnName;
}

if ($newColumnName = $mappedColToDbColWithTable[$column['second']] ?? null) {
$array[$key]['second'] = $newColumnName;
}

} elseif (isset($column['column'])) {
if ($newColumnName = $mappedColToDbColWithTable[$column['column']] ?? null) {
$array[$key]['column'] = $newColumnName;
}
}

// fixme: some unhandled cases?
if ($columnName === '*' || str_contains($columnName, ' as ')) { // todo: add support for column aliases
continue;
}

if ($newColumnName = $mappedColToDbColWithTable[$columnName] ?? null) {
if (is_array($column)) {
$array[$key]['column'] = $newColumnName;
} else {
$array[$key] = $newColumnName;
}
if ($column === '*' || str_contains($column, ' as ')) { // todo: add support for column aliases
continue;
}

if ($newColumnName = $mappedColToDbColWithTable[$column] ?? null) {
$array[$key] = $newColumnName;
}
}

Expand Down

0 comments on commit 3c7a44b

Please sign in to comment.