だからここに問題があります:
環境:
- モンゴイド(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 変更による自動保存とタイヤのコールバックと競合しているようです ...