【问题标题】:Loopback.io anonymous model definitionsLoopback.io 匿名模型定义
【发布时间】:2014-09-29 16:27:43
【问题描述】:

是否可以使用 slc 工具定义匿名模型,或者在 json 中手动定义?例如,我有一个特定的模型成员,想要一个可重用的匿名“地址”模型,但在后端存储中没有,而是直接添加到文档中。 Mongoose 提供了与此类似的功能,但没有建模模式。如果可以的话,我会在 member.json 文件的什么地方定义这个。

{
  "name": "member",
  "base": "PersistedModel",
  "properties": {
    "fullname": {
      "type": "string",
      "required": "true",
      "length": "64",
      "doc": "User's full name"
    },
    "displayname": {
      "type": "string",
      "required": "true",
      "length": "64",
      "doc": "User's display name"
    },
    "address": {
      "type": [
        "Address"
      ],
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": []
}

【问题讨论】:

    标签: json node.js model anonymous


    【解决方案1】:

    解决方案是使用“embedsMany”关系类型。

    "relations": {
        "addresses": {
            "model": "address",
            "type": "embedsMany",
            "options": {
            "autoId": false,
            "validate": true
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多