In my project, the discount has and belongs to many enterprises. I have an association callback rule that a discount cannot delete its last businss (to maintain that there is always a businss for each discount):
has_and_belongs_to_many :businesses, before_remove: :check_count, def check_count raise 'Cannot remove latest business!' if businesses.count == 1 end
However, I realized that I could not remove the discounts. Because when I do discount.destroy , I think that he will try to delete the business, and will raise an error on time.
So, is there a way around this like some kind of :except , like in controllers?
source share