-
-
Notifications
You must be signed in to change notification settings - Fork 869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Laravel] Fix virtual fields metadata #6633
base: 4.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -109,6 +109,7 @@ private function isColumnPrimaryKey(array $indexes, string $column): bool | |||||
public function getVirtualAttributes(Model $model, array $columns): Collection | ||||||
{ | ||||||
$class = new \ReflectionClass($model); | ||||||
$columns = collect($columns); | ||||||
|
||||||
return collect($class->getMethods()) | ||||||
->reject( | ||||||
|
@@ -126,18 +127,19 @@ public function getVirtualAttributes(Model $model, array $columns): Collection | |||||
|
||||||
return []; | ||||||
}) | ||||||
->reject(fn ($cast, $name) => collect($columns)->contains('name', $name)) | ||||||
->reject(fn ($cast, $name) => $columns->contains('name', $name)) | ||||||
->map(fn ($cast, $name) => [ | ||||||
'name' => $name, | ||||||
'type' => null, | ||||||
'increments' => false, | ||||||
'nullable' => null, | ||||||
'nullable' => true, | ||||||
'default' => null, | ||||||
'unique' => null, | ||||||
'fillable' => $model->isFillable($name), | ||||||
'hidden' => $this->attributeIsHidden($name, $model), | ||||||
'appended' => $model->hasAppended($name), | ||||||
'cast' => $cast, | ||||||
'primary' => $name === $model->getKeyName(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Lines 55 to 56 in 80fc2d2
In MongoDB, "id" ends as a "virtual field" because we have an accessor for it: https://github.com/mongodb/laravel-mongodb/blob/5.0.2/src/Eloquent/DocumentModel.php#L78-L94 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might also want to do this on line 83 in the same class and remove the |
||||||
]) | ||||||
->values(); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
nullable
field must be a boolean, as it is given to thenew Type()
here:core/src/Laravel/Eloquent/Metadata/Factory/Property/EloquentPropertyMetadataFactory.php
Lines 73 to 81 in 80fc2d2