我想为需要加载一些关联的某些羽毛服务调用。问题是,当我使用钩子以“羽毛方式”进行操作时,钩子不是一次性的,而是继续使用。有没有办法做一个“羽毛方式一次性关联”?钩子应该destroyed
在调用之后。
目前:
serviceAccountAssosiations() {
return function (hook) {
const walletModel = hook.app.service('wallets').Model;
const currencyModel = hook.app.service('currencies').Model;
const assetClassModel = hook.app.service('asset-classes').Model;
const exchangeModel = hook.app.service('exchanges').Model;
const bankModel = hook.app.service('banks').Model;
const valueAccountModel = hook.app.service('value-accounts').Model
const valueAccountTransactionModel = hook.app.service('value-account-transactions').Model
const walletTransactionsModel = hook.app.service('wallet-transactions').Model
const association = {
include: [
{ model: exchangeModel },
{ model: bankModel },
{ model: valueAccountModel, include: [{ model: valueAccountTransactionModel },{ model: currencyModel }] },
{ model: walletModel, include: [{ model: walletTransactionsModel },{ model: currencyModel },{ model: assetClassModel }] }
]
};
switch (hook.type) {
case 'before':
hook.params.sequelize = Object.assign(association, { raw: false });
return Promise.resolve(hook);
break;
case 'after':
dehydrate( association ).call(this, hook);
break;
}
}
}
get (id, params) {
console.log('id', id)
let app = this.options.app;
return app.service('service-accounts').hooks({
before: {
all: [this.serviceAccountAssosiations()]
},
after: {
all: [this.serviceAccountAssosiations()]
}
})
.get(id)
.then((data) => {
return data;
});
}