is it possible to modify magic field updated_at so it will update only when ceratin columns are changed? if not, I guess I have to do it on my own. In that case, how do I tell if a field has changed in the, say, before_save callback? I guess I can do something like this def foo=(val) if self.foo!=val super self.foo_changed = true end end will that do? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Off the top of my head could you do something like this? Give it try. def updated_at Time.now if attributes_changed? end protected def attributes_changed? stale_record = self.reload self.foo != stale_record.foo end Although that does force a read from the database. HTH, Nicholas On Dec 16, 2:45 pm, rubynuby <dear...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> is it possible to modify magic field updated_at so it will update only > when ceratin columns are changed? > > if not, I guess I have to do it on my own. In that case, how do I > tell if a field has changed in the, say, before_save callback? > > I guess I can do something like this > > def foo=(val) > if self.foo!=val > super > self.foo_changed = true > end > end > > will that do?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 16, 2007, at 9:44 PM, Nicholas Henry wrote:> Off the top of my head could you do something like this? Give it try. > > def updated_at > Time.now if attributes_changed? > end > > protected > > def attributes_changed? > stale_record = self.reload > self.foo != stale_record.foo > end >There are a couple of plugins that provide that: http://agilewebdevelopment.com/plugins/acts_as_modified http://agilewebdevelopment.com/plugins/activerecordchanged (I haven''t used any.) -- fxn --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 16, 2007, at 8:45 PM, rubynuby wrote:> is it possible to modify magic field updated_at so it will update only > when ceratin columns are changed?You can turn automatic timestamps off this way: MyModel.record_timestamps = false So in a callback you could check whether the columns have been changed with this plugin: http://agilewebdevelopment.com/plugins/changed_attributes and set the flag accordingly. -- fxn --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---