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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:49:16+00:00 2026-06-14T15:49:16+00:00

I completly forgot, over night, how to create the migration for this type of

  • 0

I completly forgot, over night, how to create the migration for this type of relationship:

I have a project table and a user table and each user has their own projects that they create how ever users may share the project they create either upon creating or editin the project so the relation ship is:

each project may have many users and belongs to user while each user has many projects and belongs to a project.

the problem?

I am not sure how to make a migration from this >.> as I was told I need to create a new table to stipulate this relationship.

I was thinking

generate migration project_user project_id :int user_id :int

is that any where right?

  • 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-06-14T15:49:18+00:00Added an answer on June 14, 2026 at 3:49 pm

    You need a total of 3 tables: users, projects, and project_editor_links

    Your migrations:

    create_table :users do |t|
      # user stuff
    end
    
    create_table :projects do |t|
      t.references :user
      # project stuff
    end
    
    create_table :project_editor_links |t|
      t.references :user
      t.references :project
    end    
    

    To generate that last table from the command-line:

    rails g migration project_editor_links project:references user:references
    

    Your models should look something like this:

    class User < ActiveRecord::Base
      has_many :projects
      has_many :project_editor_links
      has_many :edited_projects, :through => :project_editor_links
    end
    
    class Project < ActiveRecord::Base
      belongs_to :user
      has_many :project_editor_links
      has_many :editors, :through => :project_editor_links
    end
    
    class ProjectEditorLinks < ActiveRecord::Base
      belongs_to :editor, :class_name => 'User', :foreign_key => :user_id
      belongs_to :edited_project, :class_name => 'Project', :foreign_key => :project_id
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a per-user file browsing/uploading application using Django and when I run this
I have a ListView with an image over the right hand side. and I
I have a listbox bound to a view model observable collection: This works fine,
I wrote a stored procedure and created a temp table #TempHitRatioTable. I forgot to
In my User singleton, I have the following method: - (void)updateUser:(NSDictionary*)userInfo { //uid, fullname,
There is a wizard that can contain over 150 questions or just 10. Each
I have 2 tables. 1 has entity's, 1 per row. Another is simply a
I have a nice easy problem for you here. This is a nice easy
I've recently completed a project in Java,and showed it to my advisor. Forget about
Completely new to most of this stuff, but basically Im playing around with the

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.