Related data deletion, how to ovveride it?


I need to override a related data deletion operation because the SQL request generated is obviously wrong.

sequelize:sql:pg Executing (default): DELETE FROM "public"."user_hobby" WHERE "userId" IN ('8a38bf94-f707-41d6-a243-c1c36e1ab309|1408') +3ms

DELETE /forest/user/8a38bf94-f707-41d6-a243-c1c36e1ab309/relationships/userHobbies?delete=true 422 134 - 72.044 ms

Neither in the users routes or user-hobbies routes I have the possibility to override the route above.

Could you please help me ?

Hello @alexis,

Welcome to the Forest Admin community! :grinning_face_with_smiling_eyes:

Do you have any idea why your id includes a pipe?
Did you check your database records?

You can find in the documentation how to override the delete route for your collection.

Let me know if it helps :slight_smile:

My record is completely fine, I don’t have such pipe or something.

I know how to override a route. I didn’t know where to override this specific route.
Grepping in the whole forest admin backend codebase with relationships/userHobbies and 0 results.

I already mentioned that but again: I am in a related data table. Not in the collection one.

This video could help you to visualize what I am doing @Guillaume_Cisco :slight_smile:

Hello Alexis,

Could you check again the documentation to be sure we are not missing anything please :slight_smile:

You can override this route for achieving what your looking for:

DELETE /forest/{modelName}/{id}/relationships/{hasManyRelationName}
⟶ Dissociate records from relations
1 Like

The pipe is provided in the data: id you are concatenating the id of the related resource and the id of the current user. Is it a bug ?

I will fix that on my side but I think it’s a bug.

Hey @alexis,

Could you share the request sent to DELETE /forest/{modelName}/{id}/relationships/{hasManyRelationName} :thinking: ? This will tell. me if that comes from the UI or forest-express-sequelize

Hi @vince !

query { delete: 'true' }
body {
  data: [
      id: 'b61981f1-3ba3-4193-859f-651569208f2d|1707',
      type: 'user-hobby'
params { recordId: undefined }

DELETE /forest/user/b61981f1-3ba3-4193-859f-651569208f2d/relationships/userHobbies?delete=true

My record is issued from a many to many table without a primary key.

1 Like

My record is issued from a many to many table without a primary key.

Oh okey so that’s the issue :sweat_smile:
In that case a primary key is build with the user and something like the index. So it’s not a bug but more like not implemented I think :sweat_smile: