[LRUG] How does Rails decide how to parse ambiguous dates?
John Winters
john at sinodun.org.uk
Tue Jul 26 09:10:07 PDT 2011
On 26/07/11 16:56, Liam McAndrew wrote:
> John,
>
> I believe the clue is to look here:
> http://apidock.com/rails/ActiveRecord/AttributeMethods/read_attribute
>
> View the source and note the 'column.type_cast' line...
>
> http://apidock.com/rails/ActiveRecord/ConnectionAdapters/Column/type_cast
>
> Again view the source, the case statement refers to the 'type'
> attribute, which is actually an instance variable for the
> 'simplified_type' method...
>
> http://apidock.com/rails/ActiveRecord/ConnectionAdapters/Column/simplified_type
>
> And that's where the magic appears to happen!
Hah! So, please correct me if I'm wrong here...
When my Era record is sitting in memory, it actually contains my date as
a string, say "2011-07-26" in the format in which it would expect to
write it to the database. Then whenever I try to access it by any
normal method, it's automagically converted into a Date type.
The magic that's happening in this instance is actually that it's *not*
being converted. The reason I couldn't see where the conversion took
place is because - there is no conversion.
Have I got it now?
Cheers,
John
More information about the Chat
mailing list