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

Fix typecasting array of integers #13451

Merged
merged 1 commit into from
Dec 22, 2013
Merged

Fix typecasting array of integers #13451

merged 1 commit into from
Dec 22, 2013

Conversation

dmathieu
Copy link
Contributor

When typecasting an array of integers, if the value happens to be provided as strings (in forms for example), quote_and_escape will receive a Numeric and try gsubing on it.
This fixes it, returning the value without modifying it.

Closes #13444

def test_type_cast_integers
x = PgArray.new(ratings: ['1', '2'])
assert x.save!
assert_equal(['1', '2'], x.ratings)
Copy link
Member

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) ?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🌻

senny added a commit that referenced this pull request Dec 22, 2013
@senny senny merged commit c0a6ffb into rails:master Dec 22, 2013
senny added a commit that referenced this pull request Dec 22, 2013
@dmathieu dmathieu deleted the quoting_non_strings branch December 22, 2013 17:15
@dmathieu
Copy link
Contributor Author

Thank you Yves 😘

@schneems
Copy link
Member

Thanks to both of you! ❤️

senny added a commit that referenced this pull request Dec 22, 2013
senny added a commit that referenced this pull request Dec 22, 2013
Conflicts:

	activerecord/CHANGELOG.md
senny added a commit that referenced this pull request Dec 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undefined method `gsub' for 1:Fixnum when use postgresql integer array
3 participants