Answer the question
In order to leave comments, you need to log in
How to change a model in another model's callback?
I have Category, Subcategory and Group models linked like this:
class Category
has_many :subcategories
has_many :groups
end
class Subcategory
belongs_to :category
has_many :groups
end
class Category
has_many :subcategories
has_many :groups
after_save :pass_to_subcategories
private
def pass_to_subcategories
subcategories.map do |sc|
sc.groups = groups
end
end
end
Answer the question
In order to leave comments, you need to log in
even though the save operation at that point should have saved the groups for that instance
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question