【问题标题】:How to check associations feathers-sequelize in service hook如何检查服务挂钩中的关联羽毛续集
【发布时间】:2017-12-01 18:50:57
【问题描述】:

我正在使用feathersjs

我已阅读documentation

我如何执行这个方法来检查服务挂钩feathers-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 = {
  ......
};

【问题讨论】:

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


    【解决方案1】:

    正如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(如果你真的需要)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多