我尝试创建水线模型实例,以便稍后为其属性分配值并在其上调用.save()
。
在lib/waterline/model/lib/model.js
中有一条文档评论说明:
* var Person = Model.prototype;
* var person = new Person({ name: 'Foo Bar' });
* person.name # => 'Foo Bar'
我有一个模型用户,但我无法做任何这些陈述。
User.prototype
给了我undefined
,var user = new User({firstName: 'Foo'})
给了我一个错误:TypeError: User is not a constructor
。
我已经阅读了关于水线github的一些问题,但似乎没有什么对我有用。
真的没办法吗?
编辑: 这是我当前的用户模型定义
/**
* User.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
username: {
type: 'string',
unique: true,
alphanumericdashed: true
},
password: {
type: 'string'
},
email: {
type: 'string',
//email: true,
required: true,
unique: true
},
firstName: {
type: 'string',
required: true
},
lastName: {
type: 'string',
required: true
},
company: {
model: 'company'
},
//branches this user can access
branches: {
collection: 'branch',
via: 'users'
},
roles: {
collection: 'userrole',
via: 'users'
},
//array of permission modifying permissions of any of roles assigned to this user
userPermissions: {
collection: 'permission',
via: 'user',
through: 'userpermission'
},
//daily reports this user has been marked in as employee
dailyReports: {
collection: 'dailyreport',
via: 'dailyReportEmployees'
},
//events this user has been assigned to
assignedEvents: {
collection: 'event',
via: 'assignees'
},
toJSON: function () {
var obj = this.toObject();
delete obj.password;
return obj;
}
},
beforeUpdate: function (values, next) {
CipherService.hashPassword(values, function () {
next();
});
},
beforeCreate: function (values, next) {
CipherService.hashPassword(values, function () {
next();
});
}
};