我基于User创建了Admin模型: { "name": "Admin", "plural": "admins", "base": "User", "strict": true, "properties": { "email": { "type": "string", "mysql": { "dataType": "VARCHAR", "dataLength": 50 } }, "password": { "type": "string",
{ "name": "Admin", "plural": "admins", "base": "User", "strict": true, "properties": { "email": { "type": "string", "mysql": { "dataType": "VARCHAR", "dataLength": 50 } }, "password": { "type": "string", "mysql": { "dataType": "VARCHAR", "dataLength": 60 } }, }, "validations": [], "relations": {}, "acls": [], "methods": [] }
描述MySQL数据库中的Admin表显示User模型中的额外列:
+-------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | email | varchar(50) | YES | | NULL | | | password | varchar(60) | YES | | NULL | | | realm | varchar(512) | YES | | NULL | | | username | varchar(512) | YES | | NULL | | | credentials | text | YES | | NULL | | | challenges | text | YES | | NULL | | | emailVerified | tinyint(1) | YES | | NULL | | | verificationToken | varchar(512) | YES | | NULL | | | status | varchar(512) | YES | | NULL | | | created | datetime | YES | | NULL | | | lastUpdated | datetime | YES | | NULL | | +-------------------+--------------+------+-----+---------+----------------+
有没有办法避免用一些额外的道具填充表格?
您可以将以下代码添加到common / models / admin.jsmodule.exports = function(Admin) { var excludedProperties = [ 'realm', 'emailVerified', 'verificationToken', 'credentials', 'challenges', 'lastUpdated' ]; // Remove the properties from base User model that doesn't have mapped columns excludedProperties.forEach(function (p) { delete Admin.definition.rawProperties[p]; delete Admin.definition.properties[p]; delete Admin.prototype[p]; }); }