-
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
feat!: use mongodb function to check for dirtiness #2515
base: 5.x
Are you sure you want to change the base?
Conversation
Codecov ReportPatch coverage:
❗ 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 #2515 +/- ##
============================================
+ Coverage 90.64% 90.72% +0.07%
+ Complexity 758 754 -4
============================================
Files 34 34
Lines 1849 1843 -6
============================================
- Hits 1676 1672 -4
+ Misses 173 171 -2
☔ View full report in Codecov by Sentry. |
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.
This change will leverage the MongoDB driver to detect attribute changes. It will reduce bugs and make the maintenance easier.
Could you rebase onto master and add a changelog entry?
Co-Authored-By: Jérôme Tamarelle <[email protected]> Co-Authored-By: Hamid Alaei Varnosfaderani <[email protected]>
Hello, Done! Can you please review it? Thanks! |
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.
LGTM.
} | ||
|
||
return is_numeric($attribute) && is_numeric($original) | ||
&& strcmp((string) $attribute, (string) $original) === 0; | ||
return fromPHP([$attribute]) === fromPHP([$original]); |
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.
A couple of notes on this:
fromPHP
will be deprecated and is replaced byDocument::fromPHP
- Root-Level encoding is only supported for documents (i.e. any object or array with string keys)
- If
$attribute
happens to be an object (e.g. an embedded document), this conversion will not yield the correct results as only public properties are encoded, which is most likely wrong for any Model - This may not be an issue, but I'll note that using this comparison
['foo' => 'bar', 'bar' => 'foo']
and['bar' => 'foo', 'foo' => 'bar']
will not be treated as equal. That said, we don't have a good way to check BSON equality, and one may argue that two BSON documents with the same key/value pairs in different order shouldn't be considered equal.
For the time being, using this comparison may be feasible as long as we can ensure that it doesn't have side effects for embedded documents.
$this->assertEmpty($user->getDirty()); | ||
|
||
$user->birthday = new DateTime('19 august 1989'); | ||
$this->assertEmpty($user->getDirty()); | ||
} | ||
|
||
public function testGetDirty() |
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.
Please add a test using embedded documents and arrays to ensure correct behaviour.
This is rework of test for PR #1990