Kazim Zaidi wrote:
> If Product and Category models are in a habtm relationship, i.e.
> 
> class Product < ActiveRecord::Base
>   has_and_belongs_to_many :categories
> end
> 
> class Category < ActiveRecord::Base
>   has_and_belongs_to_many :products
> end
> 
> I want a piece of code to be executed every time a product is connected 
> to a category.
> Where do I put this code? Which callback (and on which model) will be 
> triggered?

Look into adding :after_add callbacks to the associations:

http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M001602


-- 
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to