I have the following scenario I am trying to configure in a Ruby on Rails app (warning: I’m a beginner here)…
I have SupportType model that defines different levels of customer support options (Silver, Gold etc) with details about what that support type covers (24/7, business day only etc).
I have another model, Client that contains all of the basic customer information data.
I need to associate a Client to a SupportType (Client Jones has Gold-level support) but can’t understand the “proper” way to set up this relationship. Neither “has_many” or “has_one” seems to apply in this case.
How do I set this up with the goal of being able to display all client details and the support parameters in one view?
TIA!
This way you can access client’s support type with
a_client.support_typeand see all the clients having gold support type withgold_support.clientsYou can’t use has_one in the Client model because in that case Rails aspects to find a client_id in the support_types DB table and it’s not the case if I understood well since many clients can have the same SupportType.
PS: Remember to add a support_type_id column to your clients DB table