Skip to content

Commit

Permalink
Merge branch '4.0' into 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jan 17, 2024
2 parents 749a2d0 + da11d4d commit 5c16d0e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,11 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

* Move documentation to the mongodb.com domain at [https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/](https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/)

## [4.1.1]

* Fix casting issues by [@stubbo](https://github.com/stubbo) in [#2705](https://github.com/mongodb/laravel-mongodb/pull/2705)
* Move documentation to the mongodb.com domain at [https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/](https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/)

## [4.1.0] - 2023-12-14

Expand All @@ -28,6 +28,10 @@ All notable changes to this project will be documented in this file.
* Avoid unnecessary data fetch for exists method by [@andersonls](https://github.com/andersonls) in [#2692](https://github.com/mongodb/laravel-mongodb/pull/2692)
* Hybrid support for MorphToMany relationship by [@hans-thomas](https://github.com/hans-thomas) in [#2690](https://github.com/mongodb/laravel-mongodb/pull/2690)

## [4.0.3] - 2024-01-17

- Reset `Model::$unset` when a model is saved or refreshed [#2709](https://github.com/mongodb/laravel-mongodb/pull/2709) by [@richardfila](https://github.com/richardfila)

## [4.0.2] - 2023-11-03

- Fix compatibility with Laravel 10.30 [#2661](https://github.com/mongodb/laravel-mongodb/pull/2661) by [@Treggats](https://github.com/Treggats)
Expand Down
26 changes: 26 additions & 0 deletions src/Eloquent/Model.php
Expand Up @@ -728,4 +728,30 @@ protected function isBSON(mixed $value): bool
{
return $value instanceof Type;
}

/**
* {@inheritDoc}
*/
public function save(array $options = [])
{
$saved = parent::save($options);

// Clear list of unset fields
$this->unset = [];

return $saved;
}

/**
* {@inheritDoc}
*/
public function refresh()
{
parent::refresh();

// Clear list of unset fields
$this->unset = [];

return $this;
}
}
15 changes: 15 additions & 0 deletions tests/ModelTest.php
Expand Up @@ -508,8 +508,10 @@ public function testUnset(): void
$user1->unset('note1');

$this->assertFalse(isset($user1->note1));
$this->assertTrue($user1->isDirty());

$user1->save();
$this->assertFalse($user1->isDirty());

$this->assertFalse(isset($user1->note1));
$this->assertTrue(isset($user1->note2));
Expand Down Expand Up @@ -538,6 +540,19 @@ public function testUnset(): void
$this->assertFalse(isset($user2->note2));
}

public function testUnsetRefresh(): void
{
$user = User::create(['name' => 'John Doe', 'note' => 'ABC']);
$user->save();
$user->unset('note');
$this->assertTrue($user->isDirty());

$user->refresh();

$this->assertSame('ABC', $user->note);
$this->assertFalse($user->isDirty());
}

public function testUnsetAndSet(): void
{
$user = User::create(['name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF']);
Expand Down

0 comments on commit 5c16d0e

Please sign in to comment.