I also thought about using app.model() instead of Model.extend(), but I don't know how to access app in the required model js files.
If you scaffolded your project using slc lb project
, the app object should be exported by the main app.js
file.
So you can get the app object this way:
// in models/example-model.js
var app = require('../app.js')
Once you have the app object, you can call app.model
as you correctly pointed out.
var properties = {
fieldOne: { type: String, required: true },
otherField: { type: Number }
};
var options = {
relations: {
collections: {
type: "belongsTo",
model: "user"
}
}
};
app.model('ExampleModel', {
properties: properties,
options: options,
dataSource: 'db' // replace with the correct name
);
// you can access the model now via
// app.models.ExampleModel