Created_on, created_at defaulting to 2000/01/01 00:00:00

Hello all,

Rails 1.0.0
created_on is being set to 2000/01/01 00:00:00

Any ideas on this ?

Thanks!

Schema is
create table user_login_history (
id int identity(1,1) not null,
user_id int not null,
created_on datetime default(getdate()) not null,
created_at datetime default(getdate()) not null,
updated_on datetime default(getdate()) not null,
constraint pk_user_login_history primary key clustered (id),
constraint fk_user_login_history_users foreign key (user_id) references
users(id)
)

ruby script/console

Time.now
=> Mon Dec 19 14:39:53 Central Standard Time 2005

ulh = UserLoginHistory.new({:user_id=>1})
=> #<UserLoginHistory:0x3a0cde8 @attributes={“created_on”=>Sat Jan 01
00:00:00 Central Standard Time 2000, “updated_on”=
Sat Jan 01 00:00:00 Central Standard Time 2000, “user_id”=>1,
“created_at”=>Sat Jan 01 00:00:00 Central Standard Time 2
000}, @new_record=true>

?> ulh.save
=> true

ulh
=> #<UserLoginHistory:0x3a0cde8 @attributes={“created_on”=>Sat Jan 01
00:00:00 Central Standard Time 2000, “updated_on”=
Mon Dec 19 15:08:52 Central Standard Time 2005, “id”=>“4”, “user_id”=>1,
“created_at”=>Sat Jan 01 00:00:00 Central Stan
dard Time 2000}, @errors=#<ActiveRecord::Errors:0x3a07a30 @errors={},
@base=#<UserLoginHistory:0x3a0cde8 …>>, @new_rec
ord=false>

Peter

Why are you giving default values to those datetime fields? By default,
Rails automatically updates ‘created_at’ and ‘updated_at’, so you never
have to set them.

I would just remove the “default …” and see what happens.

Alain

Hi,

First: you only need 1 “created” date/time field (named either
created_at OR
created_on) (the same rule applies to the “updated” date/time)

Second: can you show us your user login history model .rb code?

Regards,
EJC

On 12/19/05, Ed C. [email protected] wrote:

)

http://lists.rubyonrails.org/mailman/listinfo/rails

HI Ed,

I actually solved this one. Using defaults on the created_on/updated_on
fields short-circuits the “magic field names” functionality specified in
active_record/lib/active_record/timestamp.rb.

I removed teh default constraints from teh database and now the AR
objects
are behaving as expected with magic field names.

Regards,