-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -473,6 +473,10 @@ public function testUnset(): void | |
|
||
$user1->unset('note1'); | ||
|
||
$this->assertFalse(isset($user1->note1)); | ||
|
||
$user1->save(); | ||
|
||
$this->assertFalse(isset($user1->note1)); | ||
$this->assertTrue(isset($user1->note2)); | ||
$this->assertTrue(isset($user2->note1)); | ||
|
@@ -488,9 +492,60 @@ public function testUnset(): void | |
$this->assertTrue(isset($user2->note2)); | ||
|
||
$user2->unset(['note1', 'note2']); | ||
$user2->save(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
$this->assertFalse(isset($user2->note1)); | ||
$this->assertFalse(isset($user2->note2)); | ||
|
||
// Re-re-fetch to be sure | ||
$user2 = User::find($user2->_id); | ||
|
||
$this->assertFalse(isset($user2->note1)); | ||
$this->assertFalse(isset($user2->note2)); | ||
} | ||
|
||
public function testUnsetAndSet(): void | ||
{ | ||
$user = User::create(['name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF']); | ||
|
||
$this->assertTrue($user->originalIsEquivalent('note1')); | ||
|
||
// Unset the value | ||
$user->unset('note1'); | ||
$this->assertFalse(isset($user->note1)); | ||
$this->assertNull($user['note1']); | ||
$this->assertFalse($user->originalIsEquivalent('note1')); | ||
$this->assertTrue($user->isDirty()); | ||
$this->assertSame(['$unset' => ['note1' => true]], $user->getDirty()); | ||
|
||
// Reset the previous value | ||
$user->note1 = 'ABC'; | ||
$this->assertTrue($user->originalIsEquivalent('note1')); | ||
$this->assertFalse($user->isDirty()); | ||
$this->assertSame([], $user->getDirty()); | ||
|
||
// Change the value | ||
$user->note1 = 'GHI'; | ||
$this->assertTrue(isset($user->note1)); | ||
$this->assertSame('GHI', $user['note1']); | ||
$this->assertFalse($user->originalIsEquivalent('note1')); | ||
$this->assertTrue($user->isDirty()); | ||
$this->assertSame(['note1' => 'GHI'], $user->getDirty()); | ||
|
||
// Fetch to be sure the changes are not persisted yet | ||
$userCheck = User::find($user->_id); | ||
$this->assertSame('ABC', $userCheck['note1']); | ||
|
||
// Persist the changes | ||
$user->save(); | ||
|
||
// Re-fetch to be sure | ||
$user = User::find($user->_id); | ||
|
||
$this->assertTrue(isset($user->note1)); | ||
$this->assertSame('GHI', $user->note1); | ||
$this->assertTrue($user->originalIsEquivalent('note1')); | ||
$this->assertFalse($user->isDirty()); | ||
} | ||
|
||
public function testDates(): void | ||
|
There was a problem hiding this comment.
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! :)
There was a problem hiding this comment.
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 namedunset
.