Loopback.io-Model.json-尝试限制返回的字段时,范围包含不起作用

时间:2019-03-04 15:07:46

标签: javascript node.js loopbackjs

我有以下两个模型。两者都是相关的,我可以调用“获取内容”方法,并同时返回内容字段和用户字段。那里一切都很好。但是,我试图限制在内容模型中使用范围返回的用户字段只能返回firstName。这似乎没有任何效果,因为仍然返回了所有用户字段。如何使用范围限制返回的字段数量?

内容模型:

{
  "name": "Content",
  "base": "PersistedModel",
  "idInjection": true,
  "mixins": {
    "Author": {
      "authorField": "userId"
    }
  },
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "BooId": {
      "type": "string",
      "required": true
    },
    "Name": {
      "type": "string",
      "required": true
    },
    "Language": {
      "type": "string",
      "required": true,
      "default": "en-gb"
    },
    "Version": {
      "type": "number",
      "default": 1
    },
    "Text": {
      "type": "string",
      "required": true
    },
    "Created": {
      "type": "date",
      "defaultFn": "now"
    },
    "Tags": {
      "type": [
        "object"
      ]
    }
  },
  "hidden": ["userId", "id"],
  "validations": [],
  "relations": {
    "user": {
      "type": "belongsTo",
      "model": "user",
      "foreignKey": "userId"
    }
  },
  "scope": {
    "include": {
      "relation" : "user",
      "fields" : ["firstName"]
    }
  },
  "acls": [
    {
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$unauthenticated",
      "permission": "DENY"
    }
  ],
  "methods": {}
}

用户模型:

{
  "name": "user",
  "plural": "users",
  "base": "User",
  "idInjection": false,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "firstName": {
      "type": "string",
      "required": true
    },
    "lastName": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "content": {
      "type": "hasMany",
      "model": "user",
      "foreignKey": "userId"
    }
  },
  "acls": [],
  "methods": {}
}

0 个答案:

没有答案