Having trouble with AR 2.3.5, e.g.:
users = User.all( :select => "u.id, c.user_id", :from => "users u, connections c",
:conditions => ... )
Returns, e.g.:
=> [#<User id: 1000>]
>> users.first.attributes
=> {"id"=>1000, "user_id"=>"1000"}
Note that AR returns the id
of the model searched as numeric but the selected user_id
of the joined model as a String
, although both are int(11)
in the database schema.
How could I better form this type of query to select columns of tables backing multiple models and retrieving their natural type rather than String
? Seems like AR is punting on this somewhere. How could I coerce the returned types at AR load time and not have to tack .to_i
(etc.) onto every post-hoc access?