Loopback - The easiest way to extend an embedded model

I am using Loopback to create an API. The documentation, as a rule, is really good, but it really does not answer my question about the following: how can I extend (not replace) the built-in model?

The most promising information is obtained from this page - it determines how a class is based from another class through inheritance. This is useful, but not perfect - I would like to create relationships for user models from stock models, for example - A โ€œroleโ€ must have many โ€œPermissionsโ€.

The page I mention also shows a Javascript file located in common/models/<modelName>.js , which indicates that you can "extend" the model based on the properties and parameters that you give it. The server never ends up in a file ... For example - I put the file in common/models/role.js with the following contents:

 var properties = { exampleProperty: {type: String, required: true} }; var user = loopback.Model.extend('Role', properties); console.log('test'); 

Firstly, it does not get into the file at all (there is no console.log data). Secondly, obviously, because of the first point, it does not extend the model with the properties that I created.

Am I missing something obvious or is it just wrong?

+5
source share
1 answer

You must create a new model using slc loopback:model named user . By default, the built-in user is named user , so you can use lowercase user or even UserModel if you want. Then, when you are prompted for a model generator for the base model, select user . See https://github.com/strongloop/loopback-faq-user-management/blob/master/common/models/user.json#L3

+3
source

All Articles