Hi Is there any way to temporarily stop the updated_at field from being updated when a record is modified with ActiveRecord? I have a date field which is keeping track of when the record data was last checked by my application and my app manually updates it, of course when I do this the updated_at field is also touched making it fairly useless for finding out when the actual data was changed and instead almost duplicating the functionality of my updated_at field. Is there any way? Thanks Dave -- Posted via http://www.ruby-forum.com/.
Dave Verwer wrote:> Hi > > Is there any way to temporarily stop the updated_at field from being > updated when a record is modified with ActiveRecord? > > I have a date field which is keeping track of when the record data was > last checked by my application and my app manually updates it, of course > when I do this the updated_at field is also touched making it fairly > useless for finding out when the actual data was changed and instead > almost duplicating the functionality of my updated_at field. > > Is there any way? > > Thanks > Dave >I''m still a bit new myself, but the solutions that come to mind: 1. Don''t use yours at all (if it is completely duplicating it) - you''ve considered this, it seems 2. Ignore what Rails is doing 3. Delete the field "updated_at" so that Rails is not concerned about it 4. If your field is called "updated_at" and Rails is interfering with it, if possible, change the name of your field since "updated_at" and "updated_on" are ''magic fields'' 5. Wait for others on the list to give you a more useful answer.. Cheers Mohit.
Hi -- On Tue, 11 Jul 2006, Dave Verwer wrote:> Hi > > Is there any way to temporarily stop the updated_at field from being > updated when a record is modified with ActiveRecord? > > I have a date field which is keeping track of when the record data was > last checked by my application and my app manually updates it, of course > when I do this the updated_at field is also touched making it fairly > useless for finding out when the actual data was changed and instead > almost duplicating the functionality of my updated_at field. > > Is there any way?The first thing that comes to mind is to manually reset updated_at in your other method. But I don''t know whether you can -- it might decide that''s an update :-) On the other hand... it sounds like updated_at either isn''t what you want (because you''re having to fight it), or it is what you want but you need to track the other thing differently. For example, you could have a "checks" table, which would have a record_id field and a date field, or something like that, so that the two things weren''t in conflict inside of one table. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS, the Ruby book for Rails developers http://dablog.rubypal.com => D[avid ]A[. ]B[lack''s][ Web]log dblack@wobblini.net => me
Mohit Sindhwani wrote:> 1. Don''t use yours at all (if it is completely duplicating it) - you''ve > considered this, it seemsIts not completely duplicating it, I dont want my checked_at to update when I change other fields from my app, only when I update it from the app.> 2. Ignore what Rails is doingThis is a possibility, but a last resort because I would have to re-code most of the updated_at functionality> 3. Delete the field "updated_at" so that Rails is not concerned about it > 4. If your field is called "updated_at" and Rails is interfering with > it, if possible, change the name of your field since "updated_at" and > "updated_on" are ''magic fields''But I want that functionality for everything apart from when I update the checked_at field> 5. Wait for others on the list to give you a more useful answer.. > > Cheers > Mohit.Thanks for the response -- Posted via http://www.ruby-forum.com/.
unknown wrote:> The first thing that comes to mind is to manually reset updated_at in > your other method. But I don''t know whether you can -- it might > decide that''s an update :-)Thats an idea, I will try that but I have a feeling it will count as an update.> On the other hand... it sounds like updated_at either isn''t what you > want (because you''re having to fight it), or it is what you want but > you need to track the other thing differently. For example, you could > have a "checks" table, which would have a record_id field and a date > field, or something like that, so that the two things weren''t in > conflict inside of one table.I had considered this and its a possibility, thanks -- Posted via http://www.ruby-forum.com/.
Hello Dave,> Is there any way to temporarily stop the updated_at field from being > updated when a record is modified with ActiveRecord? > > I have a date field which is keeping track of when the record data was > last checked by my application and my app manually updates it, of course > when I do this the updated_at field is also touched making it fairly > useless for finding out when the actual data was changed and instead > almost duplicating the functionality of my updated_at field. > > Is there any way?You can disable this behaviour by setting AR::B class variable record_timestamps to false. in config/environment.rb, Rails::Initializer.run block : config.active_record.record_timestamps = false (if this doesn''t work, try instead ActiveRecord::Base.record_timestamps = false at the end of the file) If you want to set only for a given model : class Foo < ActiveRecord::Base self.record_timestamps = false end HTH, -- Jean-Fran?ois. -- ? la renverse.
Jean-Fran?ois wrote:> If you want to set only for a given model : > > class Foo < ActiveRecord::Base > self.record_timestamps = false > endPerfect! I can turn that off and then back on around my field update. Thankyou -- Posted via http://www.ruby-forum.com/.
Dave Verwer wrote:> Jean-François wrote: >> If you want to set only for a given model : >> >> class Foo < ActiveRecord::Base >> self.record_timestamps = false >> end > > Perfect! I can turn that off and then back on around my field update. > > ThankyouI have a requirement where I want to disable automatic update of updated_at field _only_ when certain attribute is changed. This is because I am I am maintaining a view_count field in the database which increments everytime the user visits a page. The count needs to be tracked but when I update view_count field, rails updates the updated_at field too. I want to stop that just for the field view_count. Any solution? Chirantan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi chirantan, You can do the set the same variable(record_timestamps) to false in before_update and reset it appropriately in after_update based on some condition whatever you want to check. Regards, NAYAK On Thu, Jan 8, 2009 at 9:12 AM, Chirantan Rajhans < rails-mailing-list@andreas-s.net> wrote:> > Dave Verwer wrote: > > Jean-François wrote: > >> If you want to set only for a given model : > >> > >> class Foo < ActiveRecord::Base > >> self.record_timestamps = false > >> end > > > > Perfect! I can turn that off and then back on around my field update. > > > > Thankyou > > I have a requirement where I want to disable automatic update of > updated_at field _only_ when certain attribute is changed. This is > because I am I am maintaining a view_count field in the database which > increments everytime the user visits a page. The count needs to be > tracked but when I update view_count field, rails updates the updated_at > field too. I want to stop that just for the field view_count. Any > solution? > > > Chirantan > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- Not updating the updated_at field
- ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates
- ActiveRecord::StatementInvalid: Mysql::Error: Lock wait timeout exceeded
- Syntax of session's updated_at field ?
- update_all not changing updated_at