Fixtures and created_at

Hi

When I use a fixture yml file to load setup data into my database my
created_at fields are always being set to ‘0000-00-00 00:00:00’

I have even tried injecting sql AND ruby code into the data field of the
yml to no avail.

Granted I could just change the default value of the field in the DB to
be “now” (Or the Db specific function) but since I’m letting migrations
take care of everything I figure it should … well… take care of
everything.

Ex yml.

entry_1:
name: foo
value: bar
created_at: now()

entry_2:
name: bin
value: baz
created_at: Time.now

entry_3:
name: woo
value: hah

Notice with entry 3 there is no created_at field but I get the same
results for created_at for all three entries.

See below.

Quoting Jean N. [email protected]:

be “now” (Or the Db specific function) but since I’m letting migrations
take care of everything I figure it should … well… take care of
everything.

Ex yml.

entry_1:
name: foo
value: bar
created_at: now()

Close. Try this:

created_at: <%= Time.now %>

Actually, this should be the default in Rails 2.x. And you can do
things like
this:

created_at: <%= 1.hour.ago.to_s(:db) %>

HTH,
Jeffrey

Hi,

On Wed, Sep 24, 2008 at 8:21 PM, Jean N.
[email protected] wrote:

When I use a fixture yml file to load setup data into my database my
created_at fields are always being set to ‘0000-00-00 00:00:00’

The fixtures code in 2.0+ should set your timestamped columns to
Time.now automatically if they’re not explicitly specified:

Can you try and boil this down to a small, repeatable testcase?

~ j.