Forum: Ruby on Rails created_on, created_at defaulting to 2000/01/01 00:00:00

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3203ed0e608d3bfae1e31282e629ffa2?d=identicon&s=25 Peter Fitzgibbons (Guest)
on 2005-12-19 22:12
(Received via mailing list)
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>
>>

--
B45eab4f18aa1bb2a44d6e657531a642?d=identicon&s=25 Alain Ravet (aravet)
on 2005-12-19 22:32
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
648805ae18e92b7c71e46f3caa23ddc8?d=identicon&s=25 Ed C. (Guest)
on 2005-12-19 22:42
(Received via mailing list)
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
3203ed0e608d3bfae1e31282e629ffa2?d=identicon&s=25 Peter Fitzgibbons (Guest)
on 2005-12-19 23:09
(Received via mailing list)
On 12/19/05, Ed C. <defeated2k4@gmail.com> 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,

--
This topic is locked and can not be replied to.