当包含Tire :: Callbacks时,mongoid has_many子节点不能通过nested_attributes保存

时间:2012-12-20 19:29:06

标签: mongoid nested-attributes tire

所以这就是问题:

上下文:

  • mongoid(2.2.6)
  • 轮胎(0.5.1)

类:

class Account
  include Mongoid::Document
  has_many :comments, auto_save: true
  accepts_nested_attributes_for :comments
end
class Comment
  include Mongoid::Document
  include Tire::Callbacks
  include Tire::Search
  belongs_to :account
end

操作:

account = Account.first
account.comments_attributes = [{content: 'super'}]
account.comments => [#<Comment content: 'super'>]

问题:

Comment.count => 0
Comment.search().count => 1
account.comments.build {content: 'super'}
account.save => true
Comment.count => 1

似乎与自动保存存在冲突,在mongoid上有nested_attributes更改和轮胎的回调......

1 个答案:

答案 0 :(得分:0)