koala
koala

Reputation: 1564

loopback.io multiple includes

I have a loopback.io API with a MongoDB database. I have a model called Project with 2 hasMany relationships

When I run I do a request: http://0.0.0.0:3000/api/Projects?filter[include][projectArticles]

I get the following response, which is good

{
    "title": "Project 1",
    "description": "My project number one",
    "dateCreated": "2015-10-31T00:00:00.000Z",
    "id": "5634b3af340faf570c7e70a8",
    "projectArticles": [
      {
        "articleName": "brick",
        "quantity": 5,
        "unitPrice": 2,
        "id": "5634b9ea5ab833960c8fbf6d",
        "projectId": "5634b3af340faf570c7e70a8"
      }
    ]
  }

and when I do: http://0.0.0.0:3000/api/Projects?filter[include][workHours] I get the right answer:

{
    "title": "Project 1",
    "description": "My project number one",
    "dateCreated": "2015-10-31T00:00:00.000Z",
    "id": "5634b3af340faf570c7e70a8",
    "workHours": [
      {
        "description": "blabla",
        "startDate": "2015-10-31T00:00:00.000Z",
        "endDate": "2015-10-31T00:00:00.000Z",
        "id": "5634e11d5f6471f10d2e0dd7",
        "workHourId": "5634b3af340faf570c7e70a8"
      },
      {
        "description": "blabla 2",
        "startDate": "2015-10-31T00:00:00.000Z",
        "endDate": "2015-10-31T00:00:00.000Z",
        "id": "5634e1265f6471f10d2e0dd8",
        "workHourId": "5634b3af340faf570c7e70a8"
      }
    ]
  }

but how do i combine the two includes in one request? so I have the following result:

{
    "title": "Project 1",
    "description": "My project number one",
    "dateCreated": "2015-10-31T00:00:00.000Z",
    "id": "5634b3af340faf570c7e70a8",
    "workHours": [
      {
        "description": "blabla",
        "startDate": "2015-10-31T00:00:00.000Z",
        "endDate": "2015-10-31T00:00:00.000Z",
        "id": "5634e11d5f6471f10d2e0dd7",
        "workHourId": "5634b3af340faf570c7e70a8"
      },
      {
        "description": "blabla 2",
        "startDate": "2015-10-31T00:00:00.000Z",
        "endDate": "2015-10-31T00:00:00.000Z",
        "id": "5634e1265f6471f10d2e0dd8",
        "workHourId": "5634b3af340faf570c7e70a8"
      }
    ],
    "projectArticles": [
      {
        "articleName": "brick",
        "quantity": 5,
        "unitPrice": 2,
        "id": "5634b9ea5ab833960c8fbf6d",
        "projectId": "5634b3af340faf570c7e70a8"
      }
    ]
  }

I tried this: http://0.0.0.0:3000/api/Projects?filter[include][workHours]&[include][projectArticles] but it only applies the first one and the second filter is kind of ignored

any ideas?

Upvotes: 2

Views: 1570

Answers (1)

koala
koala

Reputation: 1564

I've found the syntax for doing it

 http://0.0.0.0:3000/api/Projects?filter={"include":["workHours", "projectArticles"]}

Upvotes: 4

Related Questions