-
Notifications
You must be signed in to change notification settings - Fork 21.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
Fix typecasting array of integers #13451
Conversation
Closes #13444
def test_type_cast_integers | ||
x = PgArray.new(ratings: ['1', '2']) | ||
assert x.save! | ||
assert_equal(['1', '2'], x.ratings) |
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.
shouldn't this be assert_equal([1, 2], x.ratings)
?
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 will be once we save the record.
Unfortunately, with the way things work currently, the attribute's value is what we provide it, even though the values are typed when saved in the database.
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 did some work on json
and hstore
columns a while back to cast them directly, I'll look into it for array columns too. This is another discussion though. Patch looks good.
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.
🌻
Fix typecasting array of integers
Fix typecasting array of integers
Thank you Yves 😘 |
Thanks to both of you! ❤️ |
Conflicts: activerecord/CHANGELOG.md
When typecasting an array of integers, if the value happens to be provided as strings (in forms for example),
quote_and_escape
will receive aNumeric
and try gsubing on it.This fixes it, returning the value without modifying it.
Closes #13444