Data not available in a scope filter

Hello, I am trying to create a scope filter in a table “C”. A data in this table refer to a table “B”. It is then proposed to me to select a sub filter.

But in the list of sub-filters the data I want to retrieve which is in fact a relationship ID to another table “A” is not present.

I thought of making a smart relation on this table “C” but unfortunately we can’t use filters on smart relations.

I need to create a filter for all my tables. Is there any solution except to modify my database to add the value of the table “A” on all my tables?

Environement name : development
Agent type & version : “forest-express-sequelize”: “^8.0.0”

Hello @Danny_Louveton :wave:,

For this you can use a Smart Relationship and then implement a Filter. I let you read the documentations but don’t hesitate to come back in case of problem :pray:

Kind regards,

Florian

1 Like

Thank you for your answer.
When I try to create BelongsTo smart relationship . The relationship is not created and I get this error that tells me about the already existing relationships of the table company.

  fields: [
    {
      field: 'company_id',
      type: 'String',
      reference: 'companies.id',
      get: function (mentorProfile) {
        return models.users
          .findAll({
            where: { id: mentorProfile.userIdKey }
          })
          .then((users) => {
            return models.companies
              .findAll({
                where: { id: users[0].companyIdKey }
              })
              .then((companies) => {
                if (companies.length) return companies[0].id
              })
          })
      }
    }
  ],

From the error message, I have the impression that the smart relationship impacts my other relationships

I specify that when I remove “reference” the data are correctly displayed on forestadmin but without the relationship

How come the Smart Field works fine but it doesn’t work anymore when I add “reference” to make it a Smart Relationship?

1 Like

Hello @Danny_Louveton :wave:,

If you follow the documentation it returns the complete object and not the id, maybe your problem comes from there. :thinking:

              .then((companies) => {
                if (companies.length) return companies[0]
              })

You can also simply rename your field to “company”. I hope this will help you solve your problem :pray:

Kind regards,

Florian

1 Like