[LRUG] How does Rails decide how to parse ambiguous dates?

John Winters john at sinodun.org.uk
Tue Jul 26 09:46:39 PDT 2011


On 26/07/11 17:32, Liam McAndrew wrote:
> Not quite.  When your Era record is in memory it is a fully-fledged Era
> object, with all of its attributes type cast, so starts_at is a Date object.
>
> The "magic" happens in the adapter, so to/from the object to the database.
>
>  > era.read_attribute_before_type_cast("starts_at").class
>    => String
>
> As far as I'm aware this is just basically a utility method, it does a
> lookup on the attribute before it was type cast (which was earlier
> stored before the type cast occurred).
>
> I hope that helps clear it up slightly.

So an ActiveRecord contains all the database record fields twice?! 
Seems a wasteful (and potentially dangerous) way of doing it.

I posted the source of read_attribute_before_type_case earlier - it's just:

   def read_attribute_before_type_cast(attr_name)
     @attributes[attr_name]
   end

so it appears that @attributes contains raw, uncast data items.  The 
more normal read_attribute method is the one which does the messing about.

John



More information about the Chat mailing list