On Aug 15, 6:17 pm, Frederick C. [email protected]
wrote:
something like
def some_date
Time.at(self[:some_date])
end
def some_date= value
self[:some_date]= value.to_i
end
This provides only rudimentary support for UNIX timestamps in the
database.
For example, it breaks when I do:
named_scope :recent, lambda { { :conditions => [‘date > ?’,
1.month.ago] } }
The resulting condition on the database becomes:
WHERE (date > ‘2008-07-15 16:27:58’)
…which is not the intention: I want the Ruby time converted to a
UNIX timestamp whenever used in the database. I suspect this needs to
be done on a deeper level, possibly by monkey patching MysqlAdapter
and MysqlColumn.
In [1] Raimonds Simanovskis has a modified Oracle ConnectionAdapter
which emulates booleans stored in the database as NUMBER(1). Also, he
catches field names ending in “name” and let’s them
emulate :datetime.
I’d like to do the same with the MysqlAdapter, but I am not quite sure
what is the best way to do it.
I suppose I’d have to let MysqlColumn#simplified_type(field_type)
catch the integer fields I’d like to emulate :datetime.
But where do I perform the actual conversion? One options is to
override MysqlAdapter#select_rows – but it seems a little tedious.
Also, I need to hook in somewhere to perform the conversion the other
way – from Ruby times to UNIX timestamps in the database.
Any clues would be appreciated!
Best regards
Christian
[1]
http://blog.rayapps.com/2007/11/16/some-issues-with-oracle-views-as-activerecord-source/