【问题标题】:How can I access related models of a model instance in Loopback Android如何在 Loopback Android 中访问模型实例的相关模型
【发布时间】:2016-01-16 07:12:24
【问题描述】:

我有一个环回模型 customer,我想从 android 中的客户模型实例访问相关模型 order。但是,我找不到任何关于此的文档。有人可以帮我解决这个问题吗?

提前致谢!

{
  "name": "customer",
  "plural": "customers",
  "base": "User",
  "properties": {
    "phoneVerified": {
      "type": "boolean",
      "default": "false"
    }
  },
  "validations": [],
  "relations": {
    "roles": {
      "type": "hasMany",
      "model": "Role",
      "through": "RoleMapping",
      "foreignKey": "principalId"
    },
    "baggedProducts": {
      "type": "hasMany",
      "model": "product",
      "through": "baggedProduct",
      "foreignKey": "customerId"
    },
    "orders": {
      "type": "hasMany",
      "model": "order",
      "foreignKey": "orderId"
    }
  },
  "acls": [],
  "methods": []
}

【问题讨论】:

    标签: android model loopbackjs strongloop


    【解决方案1】:

    根据给定的关系,模型 customer 有许多模型 order。因此,要访问给定客户的订单,请使用:

    customer.order.find({}, function(err, results) {
        if(err) throw err;
        console.log(results);
    });
    

    现在,如果您使用 URL 来获取结果:您需要找到此方法的 url,如下所示:

    {your server}/customer/{id}/orders
    

    如果您使用的是 Android SDK,请按照以下说明操作:Android SDK guide for LoopBack。

    【讨论】:

      猜你喜欢
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 2018-03-21
      相关资源
      最近更新 更多