I have two tables here both with their respective scaffold generated controllers and models:
services
id|service_type|details
service_type
id|service_type
Service_type table just holds a list of service types such as:
1. CLeaning
2. Grouting
3. Polishing
Services refers to different instances of each type of service – so a service order made for polishing would have 3 as the service_type.
When I list down the list of services I want to show the corresponding service_type.service_type entry for services.service_type where services.service_type = service_type.id
Is it possible to set up the services model to do this in Ruby on Rails?
Yes it can be modeled in rails. You need to add following relationships in your models
In
service_typemodel addIn
servicemodel addThen you need to add another field to your ‘service’ model called ‘service_type_id’ which rails will use as a foreign key.
also you will have to rename ‘service_type’ field from the services table because it will conflict with rails naming convention.
Now you are set.
will now give you all orders of that particular service type
service.service_type will give you the row from service_type model