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

  • Home
  • SEARCH
  • 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 111243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:21:14+00:00 2026-05-11T02:21:14+00:00

Another basic Rails question: I have a database table that needs to contain references

  • 0

Another basic Rails question:

I have a database table that needs to contain references to exactly two different records of a specific data type.

Hypothetical example: I’m making a video game database. I have a table for ‘Companies.’ I want to have exactly one developer and exactly one publisher for each ‘Videogame’ entry.

I know that if I want to have one company, I can just do something like:

script/generate Videogame company:references 

But I need to have both companies. I’d rather not use a join table, as there can only be exactly two of the given data type, and I need them to be distinct.

It seems like the answer should be pretty obvious, but I can’t find it anywhere on the Internet.

  • 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. 2026-05-11T02:21:14+00:00Added an answer on May 11, 2026 at 2:21 am

    Just to tidy things up a bit, in your migration you can now also do:

    create_table :videogames do |t|   t.belongs_to :developer   t.belongs_to :publisher end 

    And since you’re calling the keys developer_id and publisher_id, the model should probably be:

    belongs_to :developer, :class_name => 'Company' belongs_to :publisher, :class_name => 'Company' 

    It’s not a major problem, but I find that as the number of associations with extra arguments get added, the less clear things become, so it’s best to stick to the defaults whenever possible.

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

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It means that \foo\FOO is not an application. Perhaps you… May 11, 2026 at 11:39 am
  • added an answer My feeling is that you shouldn't have any trouble running… May 11, 2026 at 11:38 am
  • added an answer The FOR XML was new in SQL Server 2005, right?… May 11, 2026 at 11:38 am

Related Questions

Another basic Rails question: I have a database table that needs to contain references
Here's the basic idea: There is a java window (main) that opens another java
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;
Another poster asked about preferred syntax for infinite loops . A follow-up question: Why
Another question asked about determining odd/evenness in C, and the idiomatic (x & 1)
another request sorry.. Right now I am reading the tokens in one by one
another issue in IE 6... link The navbar link list has a border applied
In another question I posted yesterday, I got very good advice on how a
In another question, Mark speaks highly of IDEs, saying some people still just dont
In another question on SO I answered with code like the one below and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.