So I'm a little stumped on a validation.
A client has many gyms and has many memberships
A gym has many clients and has many memberships
A membership belongs to a gym and belongs to a client
For one of my validations I'd like to set it up as so:
Validation: A client can have only one membership with gym
My thought so far being, I need to do something like, Membership.all and check if a client_id == self[client_id] or something of that nature. If so then render json: error "client has membership" else Membership.create!(member_params)
I feel like I'm overthinking at the moment and there must be a validates shorthand for such a situation
I'm a little unsure of how to go about this. Any help would be greatly appreciated!