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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:52:16+00:00 2026-06-12T21:52:16+00:00

I’m currently designing a database model and I’ve come across an issue, where I’d

  • 0

I’m currently designing a database model and I’ve come across an issue, where I’d like some more input on what’s considered the proper way of doing things.

In the example below I have two tables, Persons and Roles.
Now 1 person may be assigned 0 or more roles.
This is pretty straight forward with a many-to-many relationship, but the tricky part comes when you want to allow the user to select which role he is currently “operating” as.

Say the user got a selection of 5 roles to choose from, and depending on which role he currently has chosen, the application will present him with different views / menus / buttons / etc.

I see two solutions here:

1: (See top part of image linked below)

In the persons table, you include a nullable FK to the many-to-many relationship (the association entity).

From Wikipedia on Associative entity

It seems ok for “other entities” to reference this relationship. I’m just not entirely sure if this includes the Roles and Persons entities.

What I like about this design is that it’s pretty easy to get a list of all allowed roles for a person, and then you simply point to one of those allowed roles, saying “you’re the current/active one”. This also feels like a good way to make sure that the user can only have a role as current, if he has access to the role… Only, I also see potential disaster here:
What if, the FK in the persons table references that relationship of another user. The DB design would allow this. It would only be code that prevents it.

2: (See bottom part of image linked below)

I keep the associative entity simple, and instead I have FK in persons table that points to a specific role in the Roles table.

The problem here is that I get even less help from the DB design with ensuring that the “current role” of a person, is a role that is actually “allowed”.

Example image

Any thoughts on this would be greatly appreciated =)

UPDATE: I’ll include another variation of the same issue.

Two entities: WorkOrders and Sites

  • 1 Site may have access to many Work orders
  • 1 WorkOrder may be accessed by many Sites

So we have a many-to-many relationship

The issue: How do we best store in database which Site is the Owner of a work order, when there can only be 1 Site that Owns a work order.

Do we have “OwnerSiteId” as a column in the WorkOrder table, or would it be ok to reference the many-to-many relationship instead, saying “that one” is the owner.

  • 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-12T21:52:17+00:00Added an answer on June 12, 2026 at 9:52 pm

    If your requirement is that
    One person can have many roles but only can have one active role
    if yes than your both designs have following pros and cons

    – Design 1. Having key of ROLE table in the PERSON table pros: it will reduce on join hence cost will be reduced on database operation. Cons: You can assign the user a role that is never been in his allowed list.

    • Design 2. Having key of Associate Entity table in the PERSON table pros:PERSON will be assigned only those ROLES which are allowed for him. Cons: One additional join cost than first approach.

    Conclusion: if I were you I will go for design 1 and ensure the role assignment from application.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

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.