Skip to content

Commit 5c16d0e

Browse files
committed
Merge branch '4.0' into 4.1
2 parents 749a2d0 + da11d4d commit 5c16d0e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
* 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/)
54

65
## [4.1.1]
76

87
* Fix casting issues by [@stubbo](https://github.com/stubbo) in [#2705](https://github.com/mongodb/laravel-mongodb/pull/2705)
8+
* 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/)
99

1010
## [4.1.0] - 2023-12-14
1111

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

31+
## [4.0.3] - 2024-01-17
32+
33+
- 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)
34+
3135
## [4.0.2] - 2023-11-03
3236

3337
- Fix compatibility with Laravel 10.30 [#2661](https://github.com/mongodb/laravel-mongodb/pull/2661) by [@Treggats](https://github.com/Treggats)

src/Eloquent/Model.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,4 +728,30 @@ protected function isBSON(mixed $value): bool
728728
{
729729
return $value instanceof Type;
730730
}
731+
732+
/**
733+
* {@inheritDoc}
734+
*/
735+
public function save(array $options = [])
736+
{
737+
$saved = parent::save($options);
738+
739+
// Clear list of unset fields
740+
$this->unset = [];
741+
742+
return $saved;
743+
}
744+
745+
/**
746+
* {@inheritDoc}
747+
*/
748+
public function refresh()
749+
{
750+
parent::refresh();
751+
752+
// Clear list of unset fields
753+
$this->unset = [];
754+
755+
return $this;
756+
}
731757
}

tests/ModelTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,10 @@ public function testUnset(): void
508508
$user1->unset('note1');
509509

510510
$this->assertFalse(isset($user1->note1));
511+
$this->assertTrue($user1->isDirty());
511512

512513
$user1->save();
514+
$this->assertFalse($user1->isDirty());
513515

514516
$this->assertFalse(isset($user1->note1));
515517
$this->assertTrue(isset($user1->note2));
@@ -538,6 +540,19 @@ public function testUnset(): void
538540
$this->assertFalse(isset($user2->note2));
539541
}
540542

543+
public function testUnsetRefresh(): void
544+
{
545+
$user = User::create(['name' => 'John Doe', 'note' => 'ABC']);
546+
$user->save();
547+
$user->unset('note');
548+
$this->assertTrue($user->isDirty());
549+
550+
$user->refresh();
551+
552+
$this->assertSame('ABC', $user->note);
553+
$this->assertFalse($user->isDirty());
554+
}
555+
541556
public function testUnsetAndSet(): void
542557
{
543558
$user = User::create(['name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF']);

0 commit comments

Comments
 (0)