My models are
class Company
has_many :admins
validate :has_one_admin_validation
private
def has_one_admin_validation
errors.add(:admins, :not_enough) if admins.size < 1
end
end
class Admin
belong_to :company
end
Now, suppose I have a controller that can remove admins. How do I prevent removing the admin (ie generate errors) if it is the only admin of its company ?
If I understand well, I have to remove the admin from the memory object, and try to "save/destroy" if by validating the company first ?