Unable to filter records based on grand parent collection

Feature(s) impacted

Advanced Filter / Search records in a collection

Observed behavior

Let’s assume we have 3 tables as below with these column names -

  • Organization - org_id(PK), org_name
  • Department - dept_id(PK), dept_name, org_id(FK)
  • Employee - emp_id(PK), emp_name, dept_id(FK)
    Currently when we try to filter a Employee collection based on org_name, we don’t get option to select organization in subfield of Department.

Expected behavior

We should get option to select organization in subfield of department when filtering employees.

Context

Please provide in this mandatory section, the relevant information about your configuration:

  • Project name: Curator
  • Team name: Developer
  • Environment name: ALL (Staging, Development, Production)
  • Agent type & version:
  • Package Version: 8.3 (forest-express-sequelize)
  • Express Version: 4.17.1
  • Sequelize Version: 6.6.5
  • Database Dialect: MySql
  • Database Version: 5.7.24

Hello @Saurav_Suman

Nested filtering is actually not supported by forest admin’s agents which are deployed on your architecture.

The only way to achieve something similar to what you want is to create a smartfield, and implement the filter method.

We’re actually working on an upgrade for the agent package which, among many things, will bring nested filtering to forest admin

It should release in a couple months.

Hey,
Thanks @anon39940173
I was able to implement smart field to support nested filtering for some collections.
But I am facing issue implementing the global search for the smart field ?

Could you please let me know if its possible to apply search on the smart fields that is fetched from grand collection ?

Below is sample code snippet for what I am trying to achieve but its not working saying “No Employees Match your search”


...
search: async function (query, /** @type {any} */ search) {
    const orgs = await models.Org.findAll({
      where: { name: { [Op.like]: `%${search}%` } },
    });
    const _where = { [Op.or]: orgs.map(
        (/** @type {{ id: any; }} */ orgs) => {
          return { orgId: orgs.id };
        }
      )};
    const depts = await models.Dept.findAll({
      where: _where,
    });
    const emps = await models.Emp.findAll({
      where: {
        [Op.or]: depts.map(
            (/** @type {{ id: any; }} */ dept) => {
              return { deptId: dept.id };
            }
          )
        },
    });

    const empConditions = emps.map(
      (/** @type {{ id: any; }} */ emp) => {
        return { id: emp.id };
      }
    );
    query.where[Op.and][0][Op.or].push({
      [Op.or]: empConditions,
    });
    return query;
  },
  ...