6
在我的項目,折扣也有屬於許多企業。我有一個回調的關聯規則,打折不能刪除其最後businss(堅持認爲總有一款適合每個打折businss):如何跳過協會回調摧毀
has_and_belongs_to_many :businesses,
before_remove: :check_count,
def check_count
raise 'Cannot remove latest business!' if businesses.count == 1
end
但是我意識到,我不能刪除優惠。因爲當我做discount.destroy
,我認爲它會嘗試刪除企業,在長期會引發錯誤。
那麼,有沒有辦法解決,像某種:except
作爲控制器?
入住這裏:http://guides.rubyonrails.org/active_record_validations_callbacks.html#skipping-callbacks – 2011-12-26 10:25:42