Home > Blockchain >  how can i connect a specific a specific model table to a specific user table?
how can i connect a specific a specific model table to a specific user table?

Time:07-25

this is my first question on stack overflow hope is understandable.

im developing a budget api with nodejs sequelize express postgressql where you can add/delete transactions and receive a balance. in the backend i have a model for the transactions with "id, concept, amount, category" and now i want to add a register/login, so i create a model user with id,username and password

but im not sure how i can connect the transactions with the users, because i want the transactions to be only accesible from an specific user example = user1 has his own transactions1 and cant see any transactions from other users and user2 has is own transactions2 and cant see any transactions from any other user how i can do this? i was thinking about a 1:1 relationship but im not sure its my first time developing a register/login so any help would be appreciate, thanks :)

CodePudding user response:

as you explain, I understand that you can make 2 tables, where they match by userId. You put a reference of the user in the transactional table, like: User Table:

id | name | age ...
1  | Ana  | 18
2  | Jake | 20

Transaction Table:

id | concept | amount | category | userId
1  |  xxx    |  20    |  school  | 1
2  |  xxx    |  30    |   food   | 1

And in the backend, you make sure to get just the transactions where the userId match with your verification of who is using your application and if this user already has a register.

After this works I recommend that you use some reliable authentication.

Hope that my answer helps you (it's my first answer too ^^)

  • Related