Ok, I am trying to destroy multiple records in a 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
My issue is that only one record ends up being destroyed.
The other is that if I use destroy! (I want an exception to be raised if it doesn't destroy), then I get an error altogether.
How do you accomplish destroying multiple records in a before_create?