Hi, does anybody know if the association callbacks like :after_add, :before_remove should work together with the :through option of a has_many association? For me it actually seems not to work. And I don''t know if it is a problem of mine or generally not a feature. The Rails API docs just state that the association callbacks work with has_many. Any ideas? Feurio --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-30 09:26 UTC
Re: has_many :through and association callbacks: Working?
On May 30, 10:19 am, Feurio <govinda.pfis...-enoGyz2oHxeELgA04lAiVw@public.gmane.org> wrote:> Hi, > > does anybody know if the association callbacks > like :after_add, :before_remove should work together with the :through > option of a has_many association? >If you look at the code: if options[:through] collection_reader_method(reflection, HasManyThroughAssociation) collection_accessor_methods(reflection, HasManyThroughAssociation, false) else add_multiple_associated_save_callbacks(reflection.name) add_association_callbacks(reflection.name, reflection.options) collection_accessor_methods(reflection, HasManyAssociation) end So it would appear not. Has many through is a bit odd since it''s actually an association proxy rather than an association collection, so some things are a bit odd. Luckily in edge rails (soon to be 2.1) Pratik tidied all that up and so I would imagine the callbacks would work. 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-/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 -~----------~----~----~----~------~----~------~--~---