-
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
[4.x] use mongodb driver to check for dirtiness #1990
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -555,13 +555,52 @@ public function testMultipleLevelDotNotation(): void | |
public function testGetDirtyDates(): void | ||
{ | ||
$user = new User(); | ||
$user->setRawAttributes(['name' => 'John Doe', 'birthday' => new DateTime('19 august 1989')], true); | ||
$user->name = 'John Doe'; | ||
$user->birthday = new DateTime('19 august 1989'); | ||
$user->syncOriginal(); | ||
$this->assertEmpty($user->getDirty()); | ||
|
||
$user->birthday = new DateTime('19 august 1989'); | ||
$this->assertEmpty($user->getDirty()); | ||
} | ||
|
||
public function testGetDirty(): void | ||
{ | ||
$ids = [ | ||
new ObjectId(), | ||
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. Add value for ObjectId please |
||
new ObjectId(), | ||
]; | ||
$item = new Item([ | ||
'numbers' => [1, 2, 3], | ||
'number' => 4, | ||
'ids' => $ids, | ||
'nullable' => 'value', | ||
'fix' => 'fix', | ||
]); | ||
$item->date = $item->fromDateTime(new DateTime('19 august 1989')); | ||
$item->dates = [$item->fromDateTime(new DateTime('19 august 1989'))]; | ||
$item->save(); | ||
|
||
$item = $item->fresh(); | ||
|
||
$item->numbers = [1, 2, '3']; | ||
$item->nullable = null; | ||
$item->new_val = 'new'; | ||
$item->number = '4'; | ||
$item->ids = [ | ||
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. Looks like strange, i suggest to replace on
or
|
||
new ObjectId((string) $ids[0]), | ||
new ObjectId((string) $ids[1]), | ||
]; | ||
$item->date = $item->fromDateTime(new DateTime('19 august 1989')); | ||
$item->dates = [$item->fromDateTime(new DateTime('19 august 1989'))]; | ||
$this->assertEquals([ | ||
'numbers' => [1, 2, '3'], | ||
'number' => '4', | ||
'nullable' => null, | ||
'new_val' => 'new', | ||
], $item->getDirty()); | ||
} | ||
|
||
public function testChunkById(): void | ||
{ | ||
User::create(['name' => 'fork', 'tags' => ['sharp', 'pointy']]); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The only problem I see is a casted attributes, probably we need to check after keys was casted back to their values.
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.
@divine Looking at the code, I don't see it is required to check for casts. The input values passed by getDirty() are uncasted:
Besides, I don't see why one should use Laravel <=6 casting system for MongoDB, I don't see a test for it in the repository either. Laravel 7 custom casts are a different story. I hope they won't make things go wrong. I've already had my custom cast implementation along side this PR in Larave 5.8 production without an issue.
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.
Well, we're dropping support for laravel 6 (no other way to drop object id auto-casting) and this branch will be focused for versions > 7.0, so that's the reason why I've asked this question.
This might be an issue with Laravel 7 when it wouldn't check dirtiness for casted objects.
Yes, there are no tests, I think a lot of tests are missing, might take a look myself (for tests).
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.
@divine Then I should send this PR on top of your own PR #1988 ?
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.
Probably no, it's not ready yet, still have something to do. I will let you know, ok?
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.
@divine I have already done some checks and coding for Laravel 7. Sounds like casting in Laravel 7 also doesn't break things.
I'll send you that PR anyway. I'll wait for you to let me work on my unset-field PR #1667 after this is done.