简体   繁体   English

回送包括两个模型

[英]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' 我正在尝试使用相关模型“ 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. 关于第一个代码为什么失败的第一个问题的答案是,因为使用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 } })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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