This project is archived and is in readonly mode.
Serialized timestamps returns strings on load
-
Rick
- State changed from new to incomplete
What does your model look like (specifically, the serialize call)?
What does your model table schema look like (specifically the value field)?
Why don't use use a datetime column type?
-
Jacob Atzen
My schema definition is:
create_table :cached_method_items do |t|
t.string :key
t.text :value
t.datetime :expires_at
t.timestamps
end
The model is hidden away in a module (I'm trying to create a plugin):
module CachedMethod #:nodoc:
class Item < ActiveRecord::Base
set_table_name "cached_method_items"
serialize :value
end
end
The reason I'm not using a datetime is that this is a cache which should be
able to cache any kind of object. Serializing hashes works fine, serializing
a hash with a timestamp works fine, just not a timestamp object on it's own.
If I look in the database I can see the timestamp is serialized as
"2008-05-14 16:59:45" - whereas if I call YAML::dump(Time.now) I get "---
2008-05-14 17:02:36.626834 +02:00\n". I'm using sqlite3 if that's of any
relevance.
-
Tarmo Tänav
- Tag set to activerecord, bug
I can confirm this problem, it's clear from http://github.com/rails/rails/tr... that every time/date value gets converted to_s instead of to_yaml (which is required for serialized attributes), and since the string the time/date value is converted to is not unserializable it is treated as just a string.
I'm not sure what would be a good fix here because clearly the quoting logic is very much divorced from any knowledge about serialization so it can't really decide on how to properly serialize time/date values for serialized columns.
