Sunny Bogawat
2010-Sep-21 11:10 UTC
rails Dirty object concept is not working with nested att
hi, I want to use dirty object with nested attributes here is my example. i have form having user and addresses field when i am editing user and after updating user inside user model i am checking for any field from user get dirty using @self.changed? method it giving me proper output in this i am doing @self.address.changed?( I Have polymorphic association in user and addresses) but it is giving me nil/false if address is changed but if i am putting @self.changed? in address model it is giving me proper output. Please anybody explain me how to use dirty object concept with model association or with nested attributes? class User < ActiveRecord::Base has_many :addresses, :as =>:addressee, :dependent => :destroy accepts_nested_attributes_for :addresses, :allow_destroy => true after_update :send_account_updated_email def send_account_updated_email self.changed //giving correct changed field name self.addresses.changed //not working self.addresses.first.changed // not working end end class Address < ActiveRecord::Base belongs_to :addressee, :polymorphic => true end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sunny Bogawat
2010-Sep-24 06:15 UTC
Re: rails Dirty object concept is not working with nested att
Hi, Anybody know how this will work? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Sep-24 07:51 UTC
Re: rails Dirty object concept is not working with nested att
On Sep 21, 12:10 pm, Sunny Bogawat <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> i have form having user and addresses field when i am editing user and > after updating user inside user model i am checking for any field from > user get dirty using @self.changed? method it giving me proper output in > this i am doing @self.address.changed?( I Have polymorphic association > in user and addresses) but it is giving me nil/false if address is > changed but if i am putting -Zk4iz/Rp5SjuByTkpuCuOQ@public.gmane.org? in address model it is > giving me proper output. > > Please anybody explain me how to use dirty object concept with model > association or with nested attributes? >Just a hunch, but I think that by the time your after_update runs the associated objects have already finished saving (so their list of dirty attributes have clearer). You could validate this by stepping through AR''s save code. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Sunny Bogawat
2010-Sep-24 07:59 UTC
Re: rails Dirty object concept is not working with nested att
Frederick Cheung wrote:> On Sep 21, 12:10�pm, Sunny Bogawat <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > Just a hunch, but I think that by the time your after_update runs the > associated objects have already finished saving (so their list of > dirty attributes have clearer). You could validate this by stepping > through AR''s save code. > > FredFred, you''re right and I have validated the same. I was hoping that someone else may have come up with a solution to this. Looks like, that;s not the case. Does anybody have suggestions? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.