简体   繁体   中英

loopback include with two models

This current code is working :

  app.models.AvionPiloteAutorisation.find({
    "where": {
      "idAvion": avion.idAvion
    },
    "include": ["pilote"]
  }, function(err, pilotes) { ... }

But this :

  app.models.AvionPiloteAutorisation.find({
    "filter": {
      "where": {
        "idAvion": avion.idAvion
      },
      "include": {
        "relation": "pilote"
      }
    }
  })

fail. It's suppose to be the same, right ?

I'm trying to add some information using related model 'Utilisateur'

  app.models.AvionPiloteAutorisation.find({
    "filter": {
      "where": {
        "idAvion": avion.idAvion
      },
      "include": {"relation": "pilote", "scope": {"include": ["utilisateur"]}}
    }
  })

What am I doing wrong ?

Thanks.

The answer to your first question asking about why your second chunk of code is failing is because the syntax involving "filter" is used when you are hitting the end point using Angular SDK.
I think this code will achieve what you are trying to do here:-

  app.models.AvionPiloteAutorisation.find({ "include":[{ "pilote": "utilisateur" }], "where":{ "idAvion": avion.idAvion } })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM