I am using loopback 3. I have two models project and project members. Project has "hasMany" relation with project members.
So far, I use http://localhost:3000/api/v1/Projectsfilter[include]=projectMember which gives me result like below :-
{
"projectName": "project 1 ",
"clientNames": {},
"projectShortCode": "string",
"projectMember": [
{
"projectId": 1,
"userId": 1,
"id": 1
},
"projectName": "project 2",
"clientNames": {},
"projectShortCode": "string",
"projectMember": [
{
"projectId": 1,
"userId": 2,
"id": 2
}
}
How do I apply filter on api that I get only those project in result which has userId = 1 ?
I'm afraid you can't filter projects by the related model property. But what you could do after the api call is to filter your array, eg. you can call something like this:
api.makeRequest(projectsURL).filter(project => project.userId === 1);
Here you can find more info about that issue: https://github.com/strongloop/loopback/issues/1754 Loopback Filter Based On Related Model Properties