sails-auth
sails-auth copied to clipboard
How to add fields to User model?
I need to profile and extra data on User, but doesn't want to change User model in module. What i need to do?
I don't know what you mean by not change the User model. That's definitely the easiest way to do it:
// api/models/User.js
var _ = require('lodash');
var _super = require('sails-permissions/api/models/User');
_.merge(exports, _super);
_.merge(exports, {
// Extend with custom logic here by adding additional fields, methods, etc.
attributes: {
name: {
type: 'string'
},
some_other_data: {
type: 'string'
}
}
});
+1 for @DaAwesomeP solution
@DaAwesomeP Absolutely! This can be the way to go.
var _super = require('sails-auth/api/models/User'); // Dev may not be using sails-permissions
@alerdenisov, If you really don't want to add profile data in User table, you can create a one-to-one mapping between your User model and Profile model. Check this link to see how to create one-to-one associations.
PS: For creating a separate model as well, you will have to create a one-to-one mapping field in the User and Profile Models. For adding the field, you will have to extend the User model as DaAwesomeP suggested. You're out of luck there IMO!
@aman-gautam while you have a very good point, how do you set the profile that the autogenerated admin uses?