Rails/ActiveRecord: save changes to a model's associated collections

前端 未结 5 1701
时光取名叫无心
时光取名叫无心 2021-01-05 08:55

Do I have to save modifications to individual items in a collection for a model, or is there a method I can call to save them when I save the model.

#save

5条回答
  •  孤街浪徒
    2021-01-05 09:36

    You have to do this yourself. Active Record does not cascade save operations in has_many relations after the initial save.

    You could automate the process with a before_save callback.

提交回复
热议问题