Skip to content

Fix Model::unset with dot field name #2582

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 29, 2023
Merged

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 28, 2023

Doing #2578 I did not test subfields.

Related to #1506

@GromNaN GromNaN requested a review from alcaeus August 28, 2023 15:37
$this->unset[$offset] = true;
if (str_contains($offset, '.')) {
// Update the field in the subdocument
Arr::forget($this->attributes, $offset);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will ignore if the field is not an array.

alcaeus
alcaeus previously approved these changes Aug 28, 2023
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM. Is this also expected to work for lists?

@GromNaN
Copy link
Member Author

GromNaN commented Aug 28, 2023

Currently it's half working because the value is not unset from the memory, but it's correctly removed from the database by the $unset operation.

I'll add tests on resetting the value after unsetting.

@GromNaN GromNaN merged commit f06f7b3 into mongodb:master Aug 29, 2023
@GromNaN GromNaN deleted the unset-dot branch August 29, 2023 09:36
@GromNaN GromNaN added this to the 4.0.0 milestone Aug 30, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants