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 ?