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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:41:07+00:00 2026-05-26T06:41:07+00:00

I have a legacy SQL schema which looks something like this: CREATE TABLE `User`

  • 0

I have a legacy SQL schema which looks something like this:

CREATE TABLE `User` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `userType` varchar(255) DEFAULT NULL,
  `seqNo` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8;

CREATE TABLE `Employee` (
  `userType` varchar(255) DEFAULT NULL,
  `id` bigint(20) NOT NULL,
  `employeeNumber` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FKB65C8D4DB07F537D` (`id`),
  CONSTRAINT `FKB65C8D4DB07F537D` FOREIGN KEY (`id`) REFERENCES `User` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

In this design, an Employee is-a User in the domain model. i.e. The employee’s “id” field is a foreign key which references User.id.

How would I encode this relationship with Rails 3.0 models and migrations?
For example, if I ran

rails g scaffold User userType:string seqNo:integer 

it would get me a Rails database migration which would generate a very similar schema, and a model which could access that table. However I am not sure what to do to get the Employee table with Employee.id as a foreign key referring to User.id, as well as getting an Employee model which can access both tables.

How can I accomplish this?

  • 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-26T06:41:08+00:00Added an answer on May 26, 2026 at 6:41 am

    There are a couple of options for Rails to use legacy database schemata, e.g. when defining your migration or when defining the relations.

    Here are some pointers:

    http://www.slideshare.net/napcs/rails-and-legacy-databases-railsconf-2009

    http://www.killswitchcollective.com/articles/45_legacy_data_migration_with_activerecord

    http://sl33p3r.free.fr/tutorials/rails/legacy/legacy_databases.html

    http://lindsaar.net/2007/11/26/connecting-active-record-to-a-legacy-database-with-stored-procedures

    http://pragdave.blogs.pragprog.com/pragdave/2006/01/sharing_externa.html

    ActiveRecord Join table for legacy Database

    I would also recommend the book “Pro Active Record” … not sure if there is a newer edition for Rails 3.

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

Sidebar

Related Questions

I have a SQL Server 2005 legacy database which has a table named user
I'm using SQL Server 2008. I have a database table that looks like this
I have a legacy mysql database and there's this table which has a few
In a legacy database (SQL Server 2000), we have a clustered index that looks
We have a legacy database which is a sql server db (2005, and 2008).
I have a legacy data table in SQL Server 2005 that has a PK
I have this legacy database for which I'm building a custom viewer using Linq
I'm working with a legacy SQL Server database which has a core table with
I have a small database which is legacy from an almost defunct project. This
I have several instances where that a section of legacy sql statements is based

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.