好的,我正在尝试销毁 before_create 中的多条记录:
class InventoryItem < ActiveRecord::Base
belongs_to :user
belongs_to :item
before_create :replace_owned_items
protected
def replace_owned_items
user = self.user
item = self.item
owned_items = user.retrieve_owned_items(item)
unless owned_items.blank?
owned_items.each do |o|
o.destroy
end
end
end
end
我的问题是只有一条记录最终被销毁。
另一个是如果我使用破坏!(如果它不破坏,我希望引发异常),然后我完全得到一个错误。
如何在 before_create 中完成销毁多条记录?