Last active
December 18, 2015 08:54
-
-
Save gamov/8fe38733012931eb3360 to your computer and use it in GitHub Desktop.
Rails: postgres adapter returns string instead of integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ris = RequestedItem.currently_requested.joins(:order_request). | |
group(:item_variant_id).select('requested_items.*, order_request.business_site_id').all | |
ris.first[:business_site_id].class == String #instead of Fixnum... | |
#with SQLite with can: | |
if ris.first[:business_site_id] == DEFAULT_SITE | |
.. | |
#but with PG, we must: | |
if ris.first[:business_site_id].try(:to_i) == DEFAULT_SITE | |
.. | |
#Another example: | |
RequestedItem.where(id: 1).select(*, 10 AS tq).first.tq.class # => String | |
# http://stackoverflow.com/questions/12571215/connection-select-value-only-returns-strings-in-postgres-with-pg-gem | |
#Tried with: Rails 3.0.20 with pg gem 0.17.1 and psql 9.3.5 on mac os x 10.8.5 | |
#Same result with Rails 3.2.22 / pg gem 0.18.4 | |
#Same setup with Rails > 4.0.10 return proper type... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's your versions for PostgreSQL, pg gem and rails?