-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add UUID initialization in model save method #26
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
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,4 +63,27 @@ public function getIncrementing() | |||||||||
|
|
||||||||||
| return $this->incrementing; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Initialize the model with unique identifiers. | ||||||||||
| * | ||||||||||
| * @param array $columns | ||||||||||
| * @return void | ||||||||||
| */ | ||||||||||
| protected function initialize(array $columns): void | ||||||||||
| { | ||||||||||
| foreach ($columns as $column) { | ||||||||||
| if (in_array($column, $this->uniqueIds()) && ! $this->{$column}) { | ||||||||||
| $this->{$column} = $this->newUniqueId(); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
Comment on lines
+73
to
+80
|
||||||||||
|
|
||||||||||
| public function save(array $options = []): bool | ||||||||||
| { | ||||||||||
| $this->initialize($this->uniqueIds()); | ||||||||||
|
||||||||||
| $this->initialize($this->uniqueIds()); | |
| if (! $this->exists) { | |
| $this->initialize($this->uniqueIds()); | |
| } |
Copilot
AI
Mar 26, 2026
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.
This PR introduces new behavior (UUID assignment during save()), but current tests only assert the format returned by newUniqueId(). Adding a test that saving a new model using HasUuids auto-populates the configured unique-id columns would help prevent regressions, especially around create vs update behavior.
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.
initialize()is currently called with$this->uniqueIds(), but inside the loop it re-checksin_array($column, $this->uniqueIds())on every iteration. That condition is redundant (and recomputesuniqueIds()repeatedly); simplifying it would make the intent clearer and avoid unnecessary work.