Skip to content
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

[6.x] Model dirty check bug fix #30565

Merged
merged 1 commit into from Nov 12, 2019
Merged

[6.x] Model dirty check bug fix #30565

merged 1 commit into from Nov 12, 2019

Conversation

@browner12
Copy link
Contributor

browner12 commented Nov 12, 2019

for attributes that are cast to any type of Object, the strict equivalency (===) will never return true, because even though the values may be equal, the Objects they reference will be different.

this changes checks if the cast type is either object or collection, both which return Objects, and uses loose equivalency to compare them.

even though date casting also returns an Object, we don't need to handle that since it's handled in the previous conditional.

the test represents a scenario that occurs when using JSON fields in MySQL. MySQL returns the value with spaces between the elements, but json_encode returns a string without spaces between the elements.

References:

#30564
#28029

for attributes that are cast to any type of Object, the strict equivalency (`===`) will never return `true`, because even though the values may be equal, the Object there reference will be different.

this changes checks if the cast type is either `object` or `collection`, both with return Objects, and uses loose equivalency to compare them.

even though date casting also returns an Object, we don't need to handle that since it's handled in the previous conditional.

the test represents a scenario that occurs when using JSON fields in MySQL. MySQL returns the value with spaces between the elements, but `json_encode` returns a string **without** spaces between the elements.
@browner12

This comment has been minimized.

Copy link
Contributor Author

browner12 commented Nov 12, 2019

to clarify, they will return true if the underlying string values are identical. but if that fails, and it falls through to try and compare the casted values, it will always be false.

{
$model = new EloquentModelCastingStub;
$model->setRawAttributes([
'objectAttribute' => '["one", "two", "three"]',

This comment has been minimized.

Copy link
@driesvints

driesvints Nov 12, 2019

Member
Suggested change
'objectAttribute' => '["one", "two", "three"]',
'objectAttribute' => '["one", "two", "three"]',
@taylorotwell taylorotwell merged commit f1cfa85 into laravel:6.x Nov 12, 2019
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.