Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending the users package of mean.io

I am trying to create an application for sports event management system using MEAN.io Since it uses the modular approach, there are different packages that comes in skeleton application like system, users, access. What i want to do is make a new package called players and it should extend the users package. The players schema would contain extra fields section and teams.So how do I extend the User Schema of users package in players package?

like image 669
bring2dip Avatar asked Sep 30 '22 21:09

bring2dip


1 Answers

You can make your players package be dependent on users.

Players.register(function(app, auth, users, database) {...});

You now have access to the database and can load the user schema with

var userModel = database.connection.model('User');

and you can use the schema.add function to extend the schema

userModel.schema.add({ scrore: 'string'});

This should add the score field to the user model

I think this might work for you. But I was told from a member of mongoose team that schema.add only works before compiling the model. See this link for more info about schema add http://mongoosejs.com/docs/api.html#schema_Schema-add

like image 198
Yonatan Ellman Avatar answered Oct 16 '22 20:10

Yonatan Ellman