0

I've set up a user model for an application. I would like each user to have access to their own records after they've logged in, e.g. orders, customers, etc. How best to implement this?

My only idea is that I add a "user" field to the records which holds the id of the user it belongs to (i.e. through parent referencing). Then add some middleware which ensures that only records linked to the currently logged in user are returned. This doesn't seem very efficient but I don't really know.

Is there a better way to model the data here?

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Apr 9, 2022 at 6:17

1 Answer 1

1

this situation depends on your DB's data relationships. For instance; 1:many,many:many, 1:1 etc.

Let's assume you have a product and user who bought that product could check it.

1 user can buy more than 1 product. so it's best to use 1:many.

but everytime when you call an user you're going to upload product data as well, that's why you need to know approximately how many data will be inserted.

user - product

  1. UserID
  2. ProductID
  3. OrderID
  4. other details...

Seller can access order by querying product id or order id, as well as Customer also can check what kind of product has been bought.

BTW, My english is not good enough, sorry for that.
Happy Coding✋

Not the answer you're looking for? Browse other questions tagged or ask your own question.