Peter Fitzgibbons
2005-Dec-19 21:10 UTC
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>>>-- ------------------------------ Joyeux Noël ------------------------------ Peter Fitzgibbons _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Alain Ravet
2005-Dec-19 21:32 UTC
Re: created_on, created_at defaulting to 2000/01/01 00:00:00
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 -- Posted via http://www.ruby-forum.com/.
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, Peter Fitzgibbons <peter.fitzgibbons-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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> > >> > > -- > ------------------------------ > Joyeux Noël > ------------------------------ > Peter Fitzgibbons > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Peter Fitzgibbons
2005-Dec-19 22:07 UTC
Re: created_on, created_at defaulting to 2000/01/01 00:00:00
On 12/19/05, Ed C. <defeated2k4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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, Peter Fitzgibbons <peter.fitzgibbons-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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> > > >> > > > > -- > > ------------------------------ > > Joyeux Noël > > ------------------------------ > > Peter Fitzgibbons > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > 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, -- ------------------------------ Joyeux Noël ------------------------------ Peter Fitzgibbons _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails