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.
Quoting Jean Nibee <rails-mailing-list@andreas-s.net>:
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()
Close. Try this:
created_at: <%= Time.now %>
Actually, this should be the default in Rails 2.x. And you can do things like
this: