Skip to content
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

Saving/refreshing model doesn't reset Model::$unset #2708

Closed
mwnciau opened this issue Jan 15, 2024 · 3 comments
Closed

Saving/refreshing model doesn't reset Model::$unset #2708

mwnciau opened this issue Jan 15, 2024 · 3 comments
Milestone

Comments

@mwnciau
Copy link

mwnciau commented Jan 15, 2024

  • Laravel-mongodb Version: 4.0.2
  • PHP Version: 8.1.19
  • Database Driver & Version: mongo 5.0

Description:

Steps to reproduce

Two reproductions:

  1. Create/load model $model
  2. Call $model->unset('field')
  3. Call $model->refresh()
  4. $model->field will always be null

And secondly:

  1. Create/load model $model
  2. Call $model->unset('field')
  3. (optional) call $model->save()
  4. Accessing $model->field will never call $model->getFieldAttribute() and will always return null.

(In the latter case, our $model->getFieldAttribute() would return an empty array if the value doesn't exist)

Expected behaviour

The Model::$unset array should be cleared on a save/refresh, and it shouldn't prevent getters from being called.

Actual behaviour

Model::$unset persists until the value is set manually, preventing any getXAttribute() getters from being called and always returning null.

@GromNaN GromNaN added this to the 4.0 milestone Jan 15, 2024
@GromNaN
Copy link
Member

GromNaN commented Jan 15, 2024

Hello @mwnciau, thanks for reporting this issue.
This feature was implemented in #2578

Do you want to create a patch to solve this issue on the branch 4.0?

Tracked in PHPORM-133

@mwnciau
Copy link
Author

mwnciau commented Jan 15, 2024

Hi @GromNaN, I believe #2578 was released in 4.0, and this is a bug with the behaviour. Once unset() is called for a field, it will bypass any getFieldAttribute() getters, and refresh() won't remove this unset state so it will always return null.

Edit: Just to note - we're only still on 4.0 because of #2703

@richardfila
Copy link
Contributor

@mwnciau WIP on a fix
#2709

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants