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

  • Home
  • SEARCH
  • 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 6821163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:30:44+00:00 2026-05-26T21:30:44+00:00

This is being more difficult than I thought: I am building a system in

  • 0

This is being more difficult than I thought: I am building a system in which users can have two roles: Sellers and Buyers. The architecture must meet this requirements:

  • A user must be at least one of them, or both. The most common case will of course be Buyer.
  • Each user type has its own profile, with different sets of fields
  • When a user registers, one of either profiles must also be created and associated to it.
  • Users will have different actions available depending on their type of profile.

I have considered different design patterns but I am not good at databases design, so I am nit sure which one to apply or how. I’ve already discarded STI, so I think the solution must be some kind of user has_many :profiles & buyer/seller belongs_to :user. But I am not sure if I should use polymorphism, through, or other kind of relationship.

  • 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-26T21:30:45+00:00Added an answer on May 26, 2026 at 9:30 pm

    I’ve built some applications that have similar requirements. I believe the best solution that would meet your requirements is has_many :through.

    class Person < ActiveRecord
      has_many :assignments
      has_many :roles, :through => :assignments
    end
    
    class Assignment < ActiveRecord
      belongs_to :person
      belongs_to :role
    end
    
    class Role < ActiveRecord
      has_many :assignments
      has_many :people, :through => :assignments
    
      validates :name, :presence => true
    
      delegates :profile, :to => :assignment
    end
    

    Database:

     people
       |-- first_name, :string
       |-- last_name, :string
    
     assignments
       |-- person_id, :integer
       |-- role_id, :integer
       |-- profile, :text
    
     roles
       |-- name, :string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This turned out to be more difficult than I thought. Basically, each day a
We have an application (well, 3) which uses Oracle 9i, however this is being
Here with another question on Images ( which seems to be more difficult than
I have often heard this term being used, but I have never really understood
I don't have much experience with javascript so I' not sure if/how this can
Despite this being one of the best error messages I've ever seen (second only
When I call: actor_ ! Exit How is this being converted into a construction
I'm trying to dynamically create buttons at runtime with PyQT4.7 However, this being my
Sorry for this not being a real question, but Sometime back i remember seeing
I know this issue being mentioned before, but resolutions there didn't apply. I'm having

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.