In rails i have two models, Groups and Users. How can i do that the user have only one group and a goupr have max 4 users?
I have tried this in users.rb belongs_to :group
and this in groups.rb has_many :users
Thanks
In rails i have two models, Groups and Users. How can i do that the user have only one group and a goupr have max 4 users?
I have tried this in users.rb belongs_to :group
and this in groups.rb has_many :users
Thanks
Use a custom validation for example:
class Group
has_many :users
validate :limit_users
private
def limit_users
errors.add('Only 4 users allowed') if users.size > 4
end
end
class User
belongs_to :group
end