Evgeniy
Evgeniy

Reputation: 41

How to check associations feathers-sequelize in service hook

I`am using feathersjs.

I have read the documentation.

How do I execute this method to check on the service hook feathers-hook, or tell me another method of check.

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 = {
  ......
};

Upvotes: 4

Views: 747

Answers (1)

musicformellons
musicformellons

Reputation: 13423

As explained here: Feathers hooks work with POJO's not with DB ORM's, and your raw: false returns an ORM.

If you really can't use raw: true then convert the ORM to a POJO:

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

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

Upvotes: 1

Related Questions