I'm using ActiveRecord in rails and I have a model named Menu, many other models belong to Menu: Ingredient, Product, ProductSize, Category, ...
And to those models other models belong to: ProductPrice belongs to Product, ...
I have an attribute named version:integer in Menu. what would the cleanest approach be to increase this integer every time model that belongs_to that menu is inserted/deleted/edited? I could probably solve this with an after_save callback in the child models but I'm not sure it that would be the best approach.
Edit: using Parandroid tip I came up with this:
class MenuObserver < ActiveRecord::Observer
observe :ingredient, :product, :menu_category, :ingredient_category, :product_type, :product_size, :product_price
def after_save(model)
model.menu.version = model.menu.version + 1;
model.menu.save!
end
end
Which works perfectly.