Skip to content

Commit 467e555

Browse files
committed
fix(laravel): fix foregin keys (relations) beeing in attributes
Closes: #6842 Signed-off-by: Tobias Oitzinger <[email protected]>
1 parent 2d59c63 commit 467e555

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Laravel/Eloquent/Metadata/ModelMetadata.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ public function getAttributes(Model $model): Collection
6767
$table = $model->getTable();
6868
$columns = $schema->getColumns($table);
6969
$indexes = $schema->getIndexes($table);
70+
$relations = $this->getRelations($model);
7071

71-
return collect($columns)
72-
->map(fn ($column) => [
72+
$collection = collect($columns)
73+
->reject(
74+
fn($column) => $relations->contains(
75+
fn($relation) => $relation['foreign_key'] === $column['name']
76+
)
77+
)
78+
->map(fn($column) => [
7379
'name' => $column['name'],
7480
'type' => $column['type'],
7581
'increments' => $column['auto_increment'],
@@ -83,6 +89,8 @@ public function getAttributes(Model $model): Collection
8389
'primary' => $this->isColumnPrimaryKey($indexes, $column['name']),
8490
])
8591
->merge($this->getVirtualAttributes($model, $columns));
92+
93+
return $collection;
8694
}
8795

8896
/**

0 commit comments

Comments
 (0)