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 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
Copy link
Contributor Author

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"]',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'objectAttribute' => '["one", "two", "three"]',
'objectAttribute' => '["one", "two", "three"]',

@taylorotwell taylorotwell merged commit f1cfa85 into laravel:6.x Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants