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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:17:14+00:00 2026-05-16T20:17:14+00:00

I have a user model (sql table) that has_one : profile. profiles have user_id

  • 0

I have a user model (sql table) that has_one : profile.
profiles have user_id to refer to an user object.
Do i really need to have profile_id column ?

What are the advantages and disadvantages ?
I guess one advantage will be the size of the table that will be 1 collumn smaller.
What are the disadvantages ?

  • 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-16T20:17:14+00:00Added an answer on May 16, 2026 at 8:17 pm

    No. You don’t need id. But you need primary key, which may be other column in table. Naturally primary key means that value must be unique and not null.

    Just create table without id column:

    create_table "profiles", :id => false, primary_key => 'user_id' do |t|
      t.integer "user_id"
      #...
    end
    

    Then in model:

    class Profile < ActiveRecord::Base
      set_primary_key 'user_id'
    end
    

    The table shouldn’t have autoincrement or sequencer created – just check that. The value should be set by you or by framework if you are using association method (user.profile.create(...)) .

    Disadvantages: Some plugins may expect ‘id’ to be PK but this means they are poorly written.

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

Sidebar

Ask A Question

Stats

  • Questions 544k
  • Answers 543k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can create a new class, subclass the standard Button,… May 17, 2026 at 6:44 am
  • Editorial Team
    Editorial Team added an answer is there any whitespace before the digit? Try /^\s*\d+\.\s*/ May 17, 2026 at 6:44 am
  • Editorial Team
    Editorial Team added an answer What you are seeking to do will not work with… May 17, 2026 at 6:44 am

Trending Tags

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

Top Members

Related Questions

So I have a User model that :has_many other models like Documents, Videos, Posts
For example, if I have a user model and I need to validate login
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
I have a model Foo which have a ForeignKey to the User model. Later,
In my user model, I have an attribute called nickname and validates as such:
Suppose you have two models, User and City, joined by a third model CityPermission:
I have a database that is stuck in single-user mode. I kill the process
So I have a form that I want the user to use to update
I have the following schema for the generation of a table/model class named Account
I have a sql file that creates a database in mysql: SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;

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.