如何在环回中分离多个.js文件的模型

时间:2018-09-05 12:14:38

标签: loopbackjs loopback

我可以在不同的.js文件上分离模型自定义逻辑,例如:

/common/models/
... MyMode.js
... MyModel.hooks.js
... MyModel.validations.js
... MyModel.json

1 个答案:

答案 0 :(得分:0)

我知道了;

需要其他文件并在model.js主文件中调用它们

let validation = require('./sample.validations');
let model = require('./sample.model');

//sample.js
module.exports = function (Sample) {
    model(Sample);
    validation(Sample);
};

//sample.model.js
module.exports = function (Sample) {
    console.log('log from model');
};

//Sample.validations.js
module.exports = function (Sample) {
    console.log('log from validations');
};