I have two rails models, MyParent and MyChild.
I'm trying to build a query using the rails .select() methods to efficiently extra a large number of rows for the database.
I want to pull back a number of columns from across the two tables, but when I reference a column which is of type datetime (or timestamp) but not in the original model, it is returned as a string.
Eg:
irb(main)> MyChild.select(['created_at as child_date', 'created_at']).first.child_date.class
=> String #Bad!!!
irb(main)> MyChild.select(['created_at as child_date', 'created_at']).first.created_at.class
=> ActiveSupport::TimeWithZone #YAY!!!!
I first encountered this problem when attempted to pull a datetime from the MyParent table using joins().
How can I tell rails that I want child_date as a ActiveSupport::TimeWithZone object?
I'm using the latest version of Rails 3.2.
CAST(child_date AS DATE)