Retrieve parent from navigation and filter grand children data

I have 3 models :

places

Places.hasMany(models.maintenanceContracts, {
      foreignKey: {
        name: 'placeIdKey',
        field: 'place_id',
      },
      as: 'maintenanceContracts',
    });

maintenanceContracts

MaintenanceContracts.belongsTo(models.maintenanceContractCategories, {
      foreignKey: {
        name: 'maintenanceContractCategoryIdKey',
        field: 'maintenance_contract_category_id',
      },
      as: 'maintenanceContractCategory',
    });

maintenanceContractsCategories

MaintenanceContractCategories.hasMany(models.maintenanceContracts, {
      foreignKey: {
        name: 'maintenanceContractCategoryIdKey',
        field: 'maintenance_contract_category_id',
      },
      as: 'maintenanceContractCategoryMaintenanceContracts',
    });

I’ve created a smart relationship in forest/places

  {
    field: 'categories',
    type: ['String'],
    reference: 'maintenanceContractCategories.id'
  }

In a nutshell, it is place => maintenanceContracts => maintenanceContractCategories and it works

In Forest Admin I display a place summary view ; i have in related data its categories, for instance :

When I display the category summary view, I find all related maintenanceContracts.

I would like to see the “place where i’m coming from” related maintenanceContracts ONLY, but from this screen I have no idea how I can filter this maintenanceContracts list.

Can you help me for this ?

Hi @JeremyV,

Filtering related data is a recent feature, introduced for forest-express-sequelize/mongoose@7.3.0 & forest_liana@4.0.0, but will not currently allow to filter using navigation/grand children context. It could be useful here still since it would allow you to manually filter the result you are getting in your related data.

I’m pushing this on our product board :raised_hands:

Thank you @jeffladiray
Is there any way I could know in which place I am currently ? so i can build a smart field which displays the current maintenance contract.

Hey @JeremyV,

I’m not sure to understand your question :sweat_smile: . Could you clarify it a little bit :pray: ?

@vince

It has evolved a bit since, so let me rephrase it :

From the place collection, I display a place summary view.
I created a categories smart relationship. So I click on “Categories” and it displays categories for this place.
Note that there is no real relationship in DB between a place and a category.

THEN, I click on one Category ; it displays the category summary view.
There, I need to display the list of contracts for this category and for the place I’m coming from.

Since, as i stated before, there is no real relationship between category and place, i have no “placeIdKey” in the category record.

BUT, in the breadcrumb, I have the path displaying the place from where I am coming.

So if I had to build a smart relationship for the categories collection, how can I know in this NodeJS smart relationship route the placeID i displayed in my first screen.

Because I have to display the contracts for this category and this place.

Right now you can’t. I’ll push your feedback to product board :wink: