belongsTo form with enum values

Feature(s) impacted

Editing a belongsTo field.

Observed behavior

Users belong to a company, and may belong to a department inside that company.
Companies thus have multiple departments. Departments belong to a company.

When editing a user’s department, all departments of all companies appear regardless of the user’s company.

Expected behavior

Only departments of the user’s company should appear.

We used to achieve this by hacking into the router’s get and checking the context of the request.

How can we achieve this post-migration?

Failure Logs

We’re getting The user record you are trying to update is invalid errors when editing users which we expect to be linked to this issue. We’re not sure however.

Context

  • Agent technology: nodejs
  • Agent (forest package) name & version: 1.40.1 with sequelize 6.37.3 and sequelize-typescript 2.1.6
  • Database type: MSSQL
  • Recent changes made on your end if any: Migrated from old agent.

I’m thinking replaceSearch is the way to go but I don’t understand how to be aware of where we’re searching from (in that case, a user record).

… Well, turns out our solution was a horrible hack from bygone eras.

Simply use a Dropdown edit widget instead of a BelongsTo Select and use a filter like company id is {{currentRecord.company.id}}.

2 Likes

Hello @kll,

I’m glad that you have found a way to resolve your issue. However, I’m not sure in which context you were working. the record edition view ? a smart action ? a workspace ?

Please mark this post as resolved if your issue is solved :pray:

1 Like

We were working in a record view, while editing a relationship (nothing smart about all of this).

I think I was trying to migrate code I wrote before the dropdown filter was an option. This post certainly seems to indicate so:
Relationship dropdown edit widget filter - how to filter dataset based on current entity - Help me! - Forest Admin Developers Community

Who knew using undocumented hacks could backfire in any way?

I’m actually noticing that this suggestion was implemented:
image

Noice. Thanks folks. We even have autocomplete.

I believe I marked my previous message as the solution, do I need to do anything else on the post?

2 Likes

No it’s all good. Thanks for the detailed feedback !

1 Like