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

PHPORM-75 Defer Model::unset($field) to the save() #2578

Merged
merged 3 commits into from
Aug 25, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 23, 2023

Fix #2566 and PHPORM-75.

  • Breaking change: All calls to $model->unset($field), $model->drop($field), unset($model[$field]), unset($model->field) must be followed by $model->save() so they are persisted.
  $user = User::find($key);
  unset($user->age);
+ $user->save();
  • Deprecate Model::drop($field), it's a duplicate of Model::unset($field). The native unset($model->field) is recommended.

  • Query\Builder::update() accept a mix of field names and update operators.

DB::collection('users')->where(...)->update([
    '$inc' => ['age' => 1],
    'last_birthday' => new UTCDateTime(),
]);

Todo:

  • changelog
  • relations
  • nested model / objects

@GromNaN GromNaN changed the title PHPORM-75 Defer Model::unset($field) to the save() PHPORM-75 Defer Model::unset($field) to the save() Aug 23, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2023

Codecov Report

Patch coverage: 78.26% and project coverage change: -0.20% ⚠️

Comparison is base (f330412) 90.83% compared to head (61cbb31) 90.64%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2578      +/-   ##
============================================
- Coverage     90.83%   90.64%   -0.20%     
- Complexity      752      758       +6     
============================================
  Files            34       34              
  Lines          1834     1849      +15     
============================================
+ Hits           1666     1676      +10     
- Misses          168      173       +5     
Files Changed Coverage Δ
src/Eloquent/Model.php 90.15% <73.68%> (-2.07%) ⬇️
src/Query/Builder.php 94.53% <100.00%> (+0.02%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

/**
* @inheritdoc
*/
public function __call($method, $parameters)
Copy link
Member

Choose a reason for hiding this comment

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

It's nice to see this gone! :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why the method unset was not declared. It might be to allow a relation named unset.

@@ -488,9 +492,56 @@ public function testUnset(): void
$this->assertTrue(isset($user2->note2));

$user2->unset(['note1', 'note2']);
$user2->save();
Copy link
Member

Choose a reason for hiding this comment

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

I believe there was a separate issue where the model was not marked as dirty - maybe assert on isDirty as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was not dirty since the change was done directly in the database.
I added the assertions on isDirty for exhautivity.

@alcaeus alcaeus merged commit e652b0c into mongodb:master Aug 25, 2023
9 of 12 checks passed
@GromNaN GromNaN deleted the PHPORM-75 branch August 25, 2023 14:42
@GromNaN GromNaN added this to the 4.0.0 milestone Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

weird unset functionality
3 participants