2012-12-20 53 views
1

因此,這裏的問題:mongoid的has_many孩子不通過nested_attributes保存時輪胎::回調包括

方面:

  • 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 

似乎有與nested_attributes自動保存更改mongoid和輪胎的回調衝突...

+0

請添加您的映射定義的相關部分,並輸出或鏈接到模型的JSON序列化(Account#to_indexed_json)的輸出。 – karmi

回答