Smart field search v8

Expected behavior

query.include parameter of a smart field search function contains some included tables (say, A and B). I am able to edit the array and add some more nested includes to table A. This is how it works in v7.

Actual behavior

query.include is an empty array in the function. I add a new include (table A and it’s nested tables). Then in the logs I see the query include tables: A, B (as in the v7 I guess) and one more A with nested tables (that was added by me). So the table A is included twice. This is in v8.

Failure Logs

Also if include is not a [{ model: A }] but a { model: A }, error parentIncludeList.forEach is thrown

Context

Please provide any relevant information about your setup.

  • Package Version: 8.3.0
  • Express Version: 4.17.1
  • Sequelize Version: 5.22.4
  • Database Dialect: mysql
  • Database Version:
  • Project Name:

Hello @Tatsyana_Slabodchyka,

Thanks for your feedback. We recently (yesterday) found the issue. We have a ticket on our internal tools. I will add this thread to be sure your updated once a fix is released. :slight_smile:

Kind regards,
Morgan

2 Likes

Hello @Tatsyana_Slabodchyka,

I’m pleased to announce that we released a new version of forest-express-sequelize ! :tada:

Could you update to the new version ? And let me know if it solves your issue

Kind regards,
Morgan

1 Like

Hi! So I updated the version locally and checked - I got an error:

[forest] 🌳🌳🌳  Unexpected error: Cannot read property 'target' of undefined
{
  "stack": "TypeError: Cannot read property 'target' of undefined\n    at .../node_modules/forest-express-sequelize/dist/utils/sequelize-compatibility.js:161:47\n    at Array.forEach (<anonymous>)\n    at removeDuplicateAssociations (.../node_modules/forest-express-sequelize/dist/utils/sequelize-compatibility.js:158:15)\n    at Object.exports.postProcess (.../node_modules/forest-express-sequelize/dist/utils/sequelize-compatibility.js:178:3)\n    at QueryOptions.get sequelizeOptions [as sequelizeOptions] (.../node_modules/forest-express-sequelize/dist/services/query-options.js:75:44)\n    at ResourcesGetter._buildQueryOptions (.../node_modules/forest-express-sequelize/dist/services/resources-getter.js:116:35)\n    at async ResourcesGetter.count (.../node_modules/forest-express-sequelize/dist/services/resources-getter.js:44:30)"
}

Hey @Tatsyana_Slabodchyka,

We are currently checking. :sweat:
Can you provide your sequelize version ?

Also, can you provide the Smart Field that give that error ?

Thanks, and sorry for the false joy.

Regards,
Morgan

  • sequelize@5.22.4
  • smart field, companyNameQuery.include[0] used to be the bA table
{
      field: 'company_name',
      type: 'String',
      reference: 'organization.organizationId',
      async get(object) {
        // ...
      },
      search(query, search) {
        const companyNameQuery = query;
        companyNameQuery.include[0] = {
          ...companyNameQuery.include[0],
          include: [{
            model: getModels().fS,
            as: 'fS',
            include: {
              model: getModels().organization,
              as: 'organization',
            },
          }],
        };
        companyNameQuery.where[Op.and][0][Op.or]
          .push(getModels().sequelize.literal(`\`bA->fS->organization\`.\`companyName\` LIKE '%${search}%'`));
        return companyNameQuery;
      },
    },
  • Thanks for the investigation :slight_smile:
1 Like

Hey @Tatsyana_Slabodchyka,

After some investigations we have spotted an error on our side, also the error sent by forest-express-sequelize was not the right one,.

We just released a new version. Let me know if it solves your issue this time. :pray:

It could also raise a sequelize error if you have a wrong include. Looking at your code the include seems suspicious. Why do you use the spread ...companyNameQuery.include[0] ?

// It should be more something like that
companyNameQuery.include.push({
    include: [{
      model: getModels().fS,
      as: 'fS',
      include: {
        model: getModels().organization,
        as: 'organization',
       },
     }],
});

Regards,
Morgan

Hello!
So if I run the sever without changing anything I got another error: Unexpected error: Include unexpected. Element has to be either a Model, an Association or an object. And the query.include in the search function is an empty array.
If I include the bA table (not fS) - it works perfectly. Though I didn’t have a chance to check the final includes (if there are any tables included multiple times)

Hey @Tatsyana_Slabodchyka,

Good news. We have developed a system that optimize your query. It automatically removes duplicated includes.

We have done this since it could be hard to understand the state of the includes when you have multiple Smart Fields, all with search functions, on the same collection.

Kind regards,
Morgan

1 Like