Transform Json field from schema into Json SmartField cause field no more visible

Disclaimer, I’m a newbie on Forest and I need to work on existent code.

Feature(s) impacted

Edition

Observed behavior

I have a JSON field named testField in schema .forestadmin-schema.json. But when I edit this field nothing is saved into my DB. It’s normal because I need to perform save on another database.

Expected behavior

So I have created in my forest-express-sequelize collection a fields entry with get/set functions on this field. But now it doesn’t appear anymore in UI

Failure Logs

Nothing fail.

Field in my .forestadmin-schema.json

{
    "field": "testField",
    "type": "Json",
    "defaultValue": null,
    "enums": null,
    "integration": null,
    "isFilterable": true,
    "isPrimaryKey": false,
    "isReadOnly": false,
    "isRequired": false,
    "isSortable": true,
    "isVirtual": false,
    "reference": null,
    "inverseOf": null,
    "validations": []
  }

The get/set functions inside my forest-express-sequelize collection

{
    field: "testField",
    type: "Json",
    get: async (obj) => {
      try {
        const test = await models.test.findOne({ where: { id: obj.id } })
        if (test) {
          return test.testField;
        } else {
          return {};
        }
      } catch (e) {
        return null;
      }
    },
    set: async (obj, data) => {
      try {
        const test = await models.test.findOne({ where: { id: obj.id } })
        if (test) {
          test.testField = data;
          await test.save();
        }
        return test;
      } catch (e) {
        return 0;
      }
    },
  }

Hello,
Do you see your field in this section when you are editing your layout ? To display the section you should click on the icon on the left of the “apimap” column (look the screenshot).


Are you restart the server? The file .forestadmin-schema.json is updated at each start when something changes on your model. You must never update this file manually.

Hello @Alban_Bertolini :wave:

Thank you for your help.

The testField was already existing into the .forestadmin-schema.json. And I could saw the field and editing it (but without persistence in my db).

No I don’t see it in edit layout. And the server is always restarted on any changes.

From the moment I’ve added the get/set functions into my forest-express-sequelize collection. This field was then no longer visible.

Can I have your project, environment and team names :pray:

** removed for security **
** removed for security **
Admin

I have only Mansa and Admins as team names. The julaya does not exsit.

It’s Admin my apologizes

No problem :slight_smile:
To debug it, can you try to rename “testField” by an other name and check if the field is displayed on your UI ?

Nothing change. Field is not shown on UI (normal or edit mode)

Ok it was just a comprehension problem on our side.

Thanks a lot for your time and sorry to have distrur :pray:

1 Like