I would write custom validation:
validate :has_users?
def has_users?
# rails 2:
errors.add_to_base "Model must have some users." if self.users.blank?
end
That would do exactly that.
Note in rails 3+ you have to use:
# rails 3+
errors.add :base, "Model must have some users." if self.users.blank?
In rails 4+ there's a built-in shortcut, so you can simply do:
validates :users, presence: true
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…