Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:26:37+00:00 2026-05-31T04:26:37+00:00

I have two tables here both with their respective scaffold generated controllers and models:

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:26:40+00:00Added an answer on May 31, 2026 at 4:26 am

    Yes it can be modeled in rails. You need to add following relationships in your models

    In service_type model add

    has_many : services
    

    In service model add

     belongs_to : service_type
    

    Then 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.

    service_type.services 
    

    will now give you all orders of that particular service type

    service.service_type will give you the row from service_type model

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: entitytype and project . Here are the create table statements:
I have two tables, both with the same columns. The first table contains original
I have two simple tables as described here... Table = Person PersonID (int, PrimaryKey)
I have two tables here both contain like lots of records in the tens
I have a bit of an architecture problem here. Say I have two tables,
I'm guessing this isn't possible, but here goes. I have two tables, and I'm
i have two tables both are related with primary-foreign key ralation and i have
Lets say that I have two tables. Table 1 is a list of vendors
I have two tables - `employee` and `department`. 1. `employee` table contains column id,employee
Here is the situation that I'm facing: I have two tables A and B.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.