Im trying to get the model User
which have a relation with Projects
.
Here is my models/user.js
*fetchUser({ payload, callback }, { call, put }) {
const user = yield call(queryUser, payload);
yield put({
type: 'setCurrentUser',
payload: user,
});
if (callback) callback();
},
What is the best practice? Where should I call the function queryProjects
?
Maybe below this line?
const user = yield call(queryUser, payload);
const projects = yield call(queryProjects, user); // new api call
First Approach
Make two models,
users
&projects
Then you can do this
Once you have data for projects you can filter the project array with user id (considering your project has something like
project.user_id
) and show them into the app.Second Approach
You can have your backend server send the project list for user in the user object.
I hope it makes sense.