如何检查关联羽毛 - 服务钩子中的sequelize

时间:2017-06-16 15:47:20

标签: javascript associations sequelize.js feathersjs feathers-sequelize

我使用feathersjs

我已阅读documentation

如何执行此方法来检查服务挂钩feather-hook,或者告诉我另一种检查方法。

const { disallow } = require('feathers-hooks-common');

function include() {
  return function (hook) {
    const productPrice = hook.app.service('product-prices').Model;
    const currencies = hook.app.service('currencies').Model;
    const edizm = hook.app.service('edizm').Model;

    const pricesShema = { model: productPrice,
      include: [
        {
          model: currencies,
          attributes: ['title', 'socr']
        },
      ]
    };

    const edizmShema = { model: edizm,
      attributes: ['title', 'detail']
    };

    let association={include: [edizmShema, pricesShema]};
    hook.params.sequelize = Object.assign(association,{ raw: false });

    return Promise.resolve(hook);
  }
}

module.exports = {
  ......
};

1 个答案:

答案 0 :(得分:0)

正如here所述: 羽毛钩子与POJO一起使用而不是DB ORM,你的raw: false返回一个ORM。

如果你真的不能使用raw: true,那么将ORM转换为POJO:

const dehydrate = require('feathers-sequelize/hooks/dehydrate');
hooks.after.find = [dehydrate(), discard('password')]

你可以convert back to an ORM(如果你真的需要)。