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 7016305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:46:02+00:00 2026-05-27T22:46:02+00:00

Quick question in RoR: Is it possible to have two fields use foreign keys

  • 0

Quick question in RoR: Is it possible to have two fields use foreign keys from the same model?

For example, I am an employee. I want two fields: my current shop, and a shop I will be moved to in the future. In my model, how can I have two fields that are both the same foriegn key, but with different values.

It’s hard to explain…

An example

EMPLOYEE TABLE
----------------------------------------------
Name        Current Shop ID       Next Shop ID
John Doe    2                     1 

SHOP TABLE
----------------------------
ID          Shop Name
1           Jims Tools
2           Johns Tools

In the Employee model, I want both Current Shop and Next Shop to be foreign keys from the Shop model.

  • 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-27T22:46:02+00:00Added an answer on May 27, 2026 at 10:46 pm
    class Employee < ActiveRecord::Base
      has_one :current_shop, :class_name => Shop
      has_one :next_shop, :class_name => Shop
    end
    
    class Shop < ActiveRecord::Base
      belongs_to :current, :class_name => Employee
      belongs_to :next, :class_name => Employee
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question. What do you think, I have a few sites that use a
Quick question that requires a long explanation.. Say I have two tables - one
Quick question here: why not ALWAYS use ArrayLists in Java? They apparently have equal
Quick question: is this kind of nesting possible? An if statement first passing a
Quick question about EJB 3 stateless bean jndi lookup from context. Does context.lookup(myBean) return
quick question : Is it possible to make a pointer that can reference a
Quick Question Lets say I have $colname = 'offer_id'; and then I want to
Quick question i imagine, but i'm having trouble getting a clear answer from googling.
Quick question: I use lots of NSObject derived classes and am wondering how to
quick question. In my user database I have 5 separate tables all containing different

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.