Many-to-many relationship question

Hello everybody.
I have a question about many to many relationships. We’re using Sequelize.
I read the Forest docs here: https://docs.forestadmin.com/documentation/reference-guide/relationships#adding-a-belongstomany-relationship-sql-only
but I’m not sure about how to set the Junction table keys in order to work with Forest.

Here is the scenario.

We have two models in a many-to-many relationship with a junction table.

The junction table has two primary keys. Each key references the key of one of the two tables. The junction table has no “single” primary key.

This works well in sequelize.
Can we use this design in Forest?

Or a “single” primary key is needed in the junction table in order to work in Forest? Like this:

So the question is:
Is a “single” primary key required in the many-to-many junction table to work with Forest many-to-many relationships?

Thank you.
Matteo

Hello @Matteo,

Thank you for your question.

Both ways to define the relationship (with or without the id) can work.

The difference, and issue you may have encountered, is when creating a record for person_car.

If person_car has an id primary key, you will be able to directly create an entry for the corresponding collection via your Forest Admin panel.

If no id primary key is defined, you will need to first create a car and then, display the car record, show its “Details”, and then create a new entry in “Person through person_car” (you can directly create the person at the same time).
Starting by the person is of course possible.

Let me know if this helps.

1 Like

Ok, thank you for the explaination, :+1: