Consider the following code:
var User = app.model('User', {
options: { base: 'User' },
relations: {
accessTokens: {
model: "AccessToken",
type: "hasMany",
foreignKey: "userId"
}
},
dataSource: 'Memory'
});
LoopBack happily ignores relations property and creates a User model without relations. The problem manifests with a mysterious crash of the application much later:
server/node_modules/loopback/lib/models/user.js:160
user.accessTokens.create({
^
TypeError: Cannot call method 'create' of undefined
at server/node_modules/loopback/lib/models/user.js:160:29
at server/node_modules/loopback/lib/models/user.js:224:7
at server/node_modules/loopback/node_modules/bcryptjs/bcrypt.min.js:40:101
[cut]
Proposal
app.model and app.dataSource should throw an error when the configuration contains unknown properties.
Consider the following code:
LoopBack happily ignores
relationsproperty and creates a User model without relations. The problem manifests with a mysterious crash of the application much later:Proposal
app.modelandapp.dataSourceshould throw an error when the configuration contains unknown properties.