Loopback: Loopbackjs Querying related model of related model via rest api

Created on 6 Sep 2017  路  3Comments  路  Source: strongloop/loopback

is there any way to query related model's related model like from post \Get:

{"order": "created_at DESC","include":[{"relation": "user"]}

But, in my user model there is a relation hasone with settings model. I want to get that also, while querying from post \Get rest api.

stale

Most helpful comment

You can include related of related like so:

{
  "include": {
    "relation": "user",
    "scope": {
      "include": {
        "relation": "settings",
        "scope": {
          "where": {
            "someSetting": true
          }
        }
      }
    }
  }
}

Keep in mind this has no effect on the outer queries. I.e. You will still get all users but the users settings will only be included if someSetting is true.

All 3 comments

You can include related of related like so:

{
  "include": {
    "relation": "user",
    "scope": {
      "include": {
        "relation": "settings",
        "scope": {
          "where": {
            "someSetting": true
          }
        }
      }
    }
  }
}

Keep in mind this has no effect on the outer queries. I.e. You will still get all users but the users settings will only be included if someSetting is true.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

Was this page helpful?
0 / 5 - 0 ratings