How do I perform a search on a smart field?

Expected behavior

I expect that by typing some text in the top search bar (over the table)
i will be able to search by my smart field

Actual behavior

It doesn’t find anything without failure logs

Context

Smart field itself:

    {
      field: 'Job title',
      type: 'String',
      get: async ({id: disputeId}) => {
          const job = await disputeService.getJob(disputeId);
          return job.title;
      },
      search: async function (query, search) {
        const ids = await disputeService.searchByJobName(search);

        var searchCondition = {
          [Op.or]: [
            { id: { [Op.in]: ids } },
          ]
        };

        query.where[Op.and][0][Op.or].push(searchCondition);
        return query;
      }
    },

Service methods I use (they work but the part where I push into query object doesnt seem to work)

    async searchByJobName(jobName) {
        const ids = sequelize.query(`
            select d.id from disputes d
            join offers o on d.offer_id = o.id
            join jobs j on o.job_id = j.id
            where j.title ilike :s;
        `, {
            replacements: { s: `%${jobName}%` },
            type: QueryTypes.SELECT
        });
        
        return ids;
    },
    async getJob(disputeId) {
        const [job] = await sequelize.query(`
            select d.id, j.* from disputes d
            join offers o on d.offer_id = o.id
            join jobs j on o.job_id = j.id
            where d.id = :did;
        `, {
            replacements: { did: disputeId },
            type: QueryTypes.SELECT
        });
        
        return job;
    },

Hello @Francois_Vongue,

Sorry for the delay.

Could you try to temporarily replace the asynchronous call (await disputeService.searchByJobName(search);) by a static list of ids?
It might be that async calls are not supported at this place.

Thank you

Yes, you are right, it works with static ids but not with promises.

But what can I do about it?

@Francois_Vongue

I’ll fill a feature request on my end to see if we can add this async support.

In the mean time, I suggest you try to replicate your query from searchByJobName in the search handler, using sequelize.literal. This should inline you SQL request within the one generated by Sequelize.

Some exemples you can use:

Apologies, this is not ideal.