How to check feather-sequelize associations in a service hook

I am using feathersjs .

I read the documentation .

How can I execute this method to check the hook of the service hook, or tell me another verification method.

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 = {
  ......
};
+4
source share
1 answer

As explained here : Pen hooks do not work with POJOs with DB ORMs, and your raw: falsereturns ORMs.

If you really canโ€™t use raw: truethen convert ORM to POJO:

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

You can convert back to ORM (if you really need to).

0

Source: https://habr.com/ru/post/1679473/


All Articles