0

Here is my scenerio. Am creating an backend with node, express and sequelize for React native mobile app. Lets assume that we have two tables - one is User and another is Wallet ( both are in 1to1 association ).

Here is my question, when i need to find a associations with Wallet table, i need to send an userId from user table ( as its the foreign key ), check this code

const {userID} = req.params;
return db.B.findOne({
        where: { userId },
        include: {
          model: db.User,
          attributes: ['name', 'email'],
        },
      })

So whats the good practice ? sending userId via params and then passing directly to the findOne query or else sending some unique userdetails like "email".

So that, i can find the user with email and then user that ID to do the second query ?

Which is good practice ?

As the second one takes two query to find the user and use that userId to find the wallet associated ?

nothingimp
  • 79
  • 7

1 Answers1

0

This is really an opinion-based question as there could be scenarios where you might want to use the email, but:

Just use the unique, permanent, non-changing identifier (user ID) instead of an email.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • You mean, instead of finding the user with email and the using the founded users userId, i should be directly using / passing userID ? – nothingimp Oct 27 '20 at 10:30