-1

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. I've tried with:

{ "include": { "relation": "user","include": {"relation":"settings"}}}

but no luck.

Asif
  • 716
  • 2
  • 15
  • 37
  • Maybe my answer to another question helps you: https://stackoverflow.com/questions/45760175/multiple-includes-on-different-depths-in-a-loopback-node-js-query/45769344#45769344 – Maryam Saeidi Sep 11 '17 at 09:55

1 Answers1

0

I've create nested relationship to related to your question.

example : teamRole.json

TeamRole > belongTo > User and Team

  "validations": [],
  "relations": {
    "team": {
      "type": "belongsTo",
      "model": "Team",
      "foreignKey": ""
    },
    "user": {
      "type": "belongsTo",
      "model": "User",
      "foreignKey": ""
    }
  }

Retrieve results

app.models.TeamRole.findOne({
      where: {
        userId: user.id
      },
      include:[ {
        relation: 'team'
      },
{
        relation: 'user'
      } ]
    },function(err,team,user){
//retrieve relational data here
});

Try this approach, hope this will helpful.

ChamalPradeep
  • 429
  • 3
  • 9