-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add UUID initialization in model save method #25
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 change alters persistence behavior by auto-populating UUID columns during save(), but there are no tests covering the new behavior. Please add/update tests to assert (1) a new model gets a UUID assigned before insert, and (2) saving an existing model does not regenerate or change its UUID/primary key.
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.
Inside
initialize(), thein_array($column, $this->uniqueIds())check is redundant when the caller already passes$this->uniqueIds(), and it also recomputesuniqueIds()on every iteration. Consider either removing the membership check entirely or computinguniqueIds()once before the loop.