Hi!I have an app with products, categories, subcategories and resellercategories.Products....belongs_to :resellercategory
has_one :subcategory, :through => :resellercategory
has_one :category, :through => :subcategorySo, there are a lot of resellercategories that are (manually) mapped to my fewer subcategories.
I have a before_save in my products model that sets if the product is complete:
def check_complete
self.complete = !image_small.blank? && !subcategory.blank?
nil
endSo, if the resellercategory that the product is related to is mapped to a subcategory, the product is marked as "complete". However, at the moment it is only updated when the product is saved, I also want it to be updated when the resellercategory is mapped to a subcategory.
Is there any good way to do this? Should I create an after_save in my resellercategory that iterates through all the products and re-saves all of them to get the field updated?
Any easier/more effective way?
Peter Vandenabeele
http://twitter.com/peter_v --
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@googlegroups.com.
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.
No comments:
Post a Comment