Fubaredness Is Contagious

Dmitriy Samovskiy’s Blog

Selecting “FIELD AS NAME” in ActiveRecord Always Returns String

July 17th, 2008 · by Dmitriy (@somic on Twitter) · No Comments

If I select “field as alt_field_name”, the value will always come out as String, not what the field actually is.

 
>> User.find(:first, :select => :created_at).created_at
=> Wed Jan 24 00:04:59 UTC 2007
>> User.find(:first, :select => "created_at").created_at
=> Wed Jan 24 00:04:59 UTC 2007
>> User.find(:first, :select => "created_at as created__at").created__at
=> "2007-01-24 00:04:59"

Tags: ruby

Related posts: