如何在对象级别覆盖has_many集合的自动保存选项?

时间:2009-12-24 02:13:07

标签: ruby-on-rails

class Article
  has_many Comments
end

class Comments
  belongs_to Article
end

# Logic for importing Comments and Ratings
a = Article.find_by_name(name)
a.comments = comments # comments list gets saved.
                      # I want to delay this
#
# some other logic
#

Article.transaction
# save Comments 
# save Ratings

end

在上面的示例中,如何禁用自动保存评论集合?

1 个答案:

答案 0 :(得分:0)

在保存文章之前,请不要保存将评论添加到文章中。