Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add fields to User model? #119

Open
alerdenisov opened this issue Dec 16, 2015 · 4 comments
Open

How to add fields to User model? #119

alerdenisov opened this issue Dec 16, 2015 · 4 comments

Comments

@alerdenisov
Copy link

I need to profile and extra data on User, but doesn't want to change User model in module. What i need to do?

@DaAwesomeP
Copy link

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'
    }
  }
});

@po5i
Copy link

po5i commented Feb 22, 2016

+1 for @DaAwesomeP solution

@aman-gautam
Copy link

@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!

@trex005
Copy link

trex005 commented Jan 25, 2018

@aman-gautam while you have a very good point, how do you set the profile that the autogenerated admin uses?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants