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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:02:31+00:00 2026-05-25T03:02:31+00:00

In my application I have 3 tables, users, lists, tasks. Users and lists is

  • 0

In my application I have 3 tables, users, lists, tasks.

Users and lists is a many-to-many relationship, tasks belong to lists, and users can complete tasks.

For my migration, when a user completes a list I’d like to store who it was completed by in the database but I’m unsure how to do this.

I could simply add t.integer :user_id to my tasks migration, though I’d like to refer to it as .completed_by. Something that references the :user_id in my User table but is named :completed_by?

  • 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-25T03:02:32+00:00Added an answer on May 25, 2026 at 3:02 am

    As MrDanA mentioned, you can specify a different foreign_key, but I would recommend against it. If you can, your db structure will be more understandable at the low level if you stay with entity name conventions.

    In the future, it’ll be immediately obvious that user_id points at the user table, while a new programmer won’t be able to tell that completed_by points at the user table without exploring code. If you do want to have a specific name, or need more than one user association, something like “completed_user_id” remains clear at both the app and db levels.

    You can then add methods like:

    has_one :user
    
    has_one :completed_by, :class_name => "User", :foreign_key => "completed_user_id"
    

    or

    has_one :user
    
    def completed_by
        self.user.id
    end
    

    etc.

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

Sidebar

Related Questions

I have users for my application with access control list (these are both tables/schema/objects).
I have two tables: 1. tableA is a list of records with many columns.
I have three tables to define users: USER: user_id (int), username (varchar) USER_METADATA_FIELD: user_metadata_field_id
I have a small application where users can login and do whatever they do
I have an application with requests which fetch lists from huge tables (7 mil+
I have an application which has a Projects table and a Users table. In
In my iPhone application I have a table view. When user taps any row,
In my application, a user has_many tickets. Unfortunately, the tickets table does not have
We have two tables in our application that both have a ShowOrder column. We
in my application I have a few CListCtrl tables. I fill/refresh them with data

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.