删除用户模型中未使用的元素

时间:2015-10-24 06:51:53

标签: strongloop

在Strongloop中,我想扩展用户模型,但有一些我不需要的字段:

username
credentials
verificationToken

当我创建数据库时,我不想为这些无用的字段创建列。围绕这个最好的方法是什么?

1 个答案:

答案 0 :(得分:0)

目前,有一个未解决的问题:A better way for customizing built-in models

如果你还想要它:解决方法是首先更新 /node_modules/loopback/common/models/user.json ,删除不需要的字段:

{
  "name": "User",
  "properties": {
    "realm": {
      "type": "string"
    },
    "password": {
      "type": "string",
      "required": true
    },
    "email": {
      "type": "string",
      "required": true
    },
    "emailVerified": "boolean",
    "status": "string",
    "created": "date",
    "lastUpdated": "date"
  },
  "hidden": ["password"],
  "acls": [
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "DENY"
    },
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "create"
    },
    {
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW",
      "property": "deleteById"
    },
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "login"
    },
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "logout"
    },
    {
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW",
      "property": "findById"
    },
    {
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW",
      "property": "updateAttributes"
    },
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "confirm"
    },
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "resetPassword",
      "accessType": "EXECUTE"
    }
  ],
  "relations": {
    "accessTokens": {
      "type": "hasMany",
      "model": "AccessToken",
      "foreignKey": "userId",
      "options": {
        "disableInclude": true
      }
    }
  }
}

注意:我也删除了挑战,因为它已被弃用。

然后你可以扩展它。对于sql数据库,您可以像 model.json

中一样创建相应的表