Forum: Ruby on Rails datetime returned as string, sometimes....

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
71c85a662af0764df3a77cc00db166c9?d=identicon&s=25 Raphael Bauduin (Guest)
on 2006-01-07 13:36
(Received via mailing list)

I'm using postgresql 8.1, rails 1.0, and I have a strange problem on a
datetime field (timestamp without time zone in postgresql).

As shown below, the field "value" sometimes returns a string, and
sometimes a Time instance, depending of where the value is used....:

* breakpoint session _from inside an instance method_ of the object:
=> "1996-05-01 00:00:00"
=> String

However, as you can see, the value field is of type datetime:

=> #<ActiveRecord::ConnectionAdapters::Column:0xb7489378 @limit=nil,
@text=false, @null=true, @primary=false, @default=nil,
@type=:datetime, @name="value", @number=false>

If I load an instance form the database, I also get a string back:
=> String

* But if I load the same instance from a console session I get a Time

=> Time

I first thought it could come from the way I created the value (
:value => "2005-01-01" or :value => DateTime.parse("2005-01-01")), but
that wasn't confirmed by my tests.

Actually, it seems to depend of the account I use to log into my
application, and the place where I put the breakpoint call! This could
make sense as the data created for the demo account is not treated
with the same code. However, I don't understand what happens as it
looks in the right table, sees it works on a datatime field, but still
returns a String, depending on where you are in the code.....

 In short this is what I found out:
demo account + breakpoint in model instance method => string
demo account + breakpoint outside model instance method ( a view eg) =>
normal user account + breakpoint in model instance method => Time

Has anyone experienced a similar thing?


71c85a662af0764df3a77cc00db166c9?d=identicon&s=25 Raphael Bauduin (Guest)
on 2006-01-07 17:00
(Received via mailing list)
I found the cause of the problem: The class Detail was derived from
another class which had the value column of type text.

This topic is locked and can not be replied to.