-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:
Autosave works great when using reference associations, but it does not appear to work through an embedded document:
class Post embeds_many :comments belongs_to :user, autosave: true end class Comment embedded_in :post belongs_to :user, autosave: true end class User end comment = Comment.new(user: User.new) post = Post.new(user: User.new) post.comments << comment post.save post.user.persisted? # => true comment.user.persisted? # => false :(
Right now, I've solved this with a before_save callback on the Post model, but it makes me sad:
class Post before_save { comments.map(&:user).select(&:new_record?).each(&:save) } end