Поиск перьев по соответствующему столбцу

Я пытаюсь отфильтровать данные на основе значения связанной таблицы, он отлично работает, когда я нахожу все, но когда я пытаюсь выполнить поиск по имени, я получаю сообщение об ошибке столбца не существует

я установил крючок, как описано в https://github.com/feathersjs-ecosystem/feathers-sequelize#associations

В почтальоне я вижу ассоциацию как подраздел, но я не могу искать ни по каким столбцам

получение кода

service.find({
        query: {
          include: ["policyholders"],
          Name: {
            $like: `%somename%`,
          },
        },
      });

модель политик

// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require("sequelize");
const DataTypes = Sequelize.DataTypes;

module.exports = function (app) {
  const sequelizeClient = app.get("sequelizeClient");
  const policies = sequelizeClient.define(
    "policies",
    {
      PolicyId: {
        autoIncrement: true,
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true,
      },
      PolicyNumber: {
        type: DataTypes.STRING(30),
        allowNull: true,
      },
      PolicyHolderId: {
        type: DataTypes.INTEGER,
        allowNull: true
      },
    },
    {
      hooks: {
        beforeCount(options) {
          options.raw = true;
        },
      },
    }
  );

  // eslint-disable-next-line no-unused-vars
  policies.associate = function (models) {
    // Define associations here
    // See http://docs.sequelizejs.com/en/latest/docs/associations/
    const { policyholders } = models;
    policies.belongsTo(policyholders, { foreignKey: "PolicyholderId" });
  };

  return policies;
};

модель страхователей

// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;

module.exports = function (app) {
  const sequelizeClient = app.get('sequelizeClient');
  const policyholders = sequelizeClient.define(
    'policyholders',
    {
      PolicyholderId: {
        autoIncrement: true,
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true,
      },
      Name: {
        type: DataTypes.STRING(250),
        allowNull: true,
      },
    },
    {
      hooks: {
        beforeCount(options) {
          options.raw = true;
        },
      },
    }
  );

  // eslint-disable-next-line no-unused-vars
  policyholders.associate = function (models) {
    // Define associations here
    // See http://docs.sequelizejs.com/en/latest/docs/associations/
    const { policies } = models;

    policyholders.hasMany(policies, { foreignKey: { name: 'PolicyholderId' } });
  };

  return policyholders;
};

крючок политик

const { authenticate } = require('@feathersjs/authentication').hooks;

const getRelated = require('../../hooks/get-related');

module.exports = {
  before: {
    all: [ authenticate('jwt') ],
    find: [getRelated()],
    get: [getRelated()],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  after: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
};

крючки связаны

module.exports = function (options = {}) {
  return async (context) => {
    const { include, ...query } = context.params.query;

    if (include) {


      const AssociatedModel = context.app.services.policyholders.Model;
      context.params.sequelize = {
        include: [{ model: AssociatedModel }],
        raw: false
      };

      
      // Update the query to not include `include`
      context.params.query = query;
    }

    return context;
  };
};

person Josh Fradley    schedule 20.04.2021    source источник


Ответы (1)


Ответ слишком

 "$policyholder.Name%": {
            $like: `%somename%`,
          },

Затем в службе перьев добавьте строку в массив белого списка.

person Josh Fradley    schedule 25.04.2021