2
b2plane
1y

If i have 4 types of user in a system, is it better to separate them each individually into their own models:
- UserA
- UserB
- UserC
- UserD

or should i group them all into 1 model:
- User

And then add an attribute Role in order to distinguish each one?

What is the proper way?

Entities:
- admin
- staff
- seller
- buyer

How would you structure these as ER diagram?

Comments
  • 11
    First Q:
    One User model with role attribute.

    Second Q:
    I wouldn’t.
  • 2
    https://splunk.com/en_us/blog/....

    You should learn a little bit about common data structure pitfalls.
  • 0
    @Lensflare @lungdart thanks. I ask this because, if i group all of the types of users in 1 entity, i will always have some fields null.

    For example lets say

    Seller:
    - first_name
    - last_name

    Is optional. It can be null or it can be set and this is available for every seller.

    Buyer:
    - Does never have to set their first and last name, these fields do not exist for the buyer, so these fields will always be null when a user registers as a buyer.

    This is just a simplified example. Now imagine the rest of the User-Related fields that will only get applied to sellers, only get applied to buyers, only get applied to admins, etc

    TLDR:
    By keeping it all as 1 user entity, some of those fields will always be null in 100% cases depending on the Role. Is this normal?
  • 0
    @b2plane one model is royally fucked if a single user is a buyer and a seller or needs correction because wrong pick.
  • 4
    you _don't_ have four types of user.

    you have _one_ type of user, and four _roles_ which users can belong to.

    there. i've solved your life now.
  • 0
    @jestdotty the teal deer is to look at the bullet points under each normalization form in the same link.

    Chat gpt is excellent at boiling down a topic like this as well.
  • 0
    @jestdotty i can only lead you to the watering hole. I can't make you drink.

    If you want more details of the points you didn't mention that were listed, feel free to read more.
Add Comment