Hi!

I have an app with products, categories, subcategories and 
resellercategories.

Products....

belongs_to :resellercategory
has_one :subcategory, :through => :resellercategory
has_one :category, :through => :subcategory

So, 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
  end

So, 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?

Regards
Linus

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/jtDjwL9A_WIJ.
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