Many to many between three tables

Issue #151 new
andreana felicione created an issue

Is it possible to map a many to many relationsheep between three tables?

I’ve tried to do that with an intermediate table with three foreign keys, but when I try to insert data with InsertOrReplaceWithChildrenAsync() the intermediate table results has all row with IdA or IdB or IdC not populated….

PS. All my three tables has not autoincrement primary key.

Comments (1)

  1. Guillermo Gutiérrez

    Hello Andreana, can you post the code of what you’ve achieved so far?

    What you describe can be simplified to a table with ManyToOne relationships to three different tables. You can also setup a ManyToMany relationship between all the three tables using the intermediate type described above for read operations when you don’t need to access the data of the intermediate table.

    An example for this would be something like this:

    • User
    • Role
    • Account

    One user can belong to an account with an associated role. In this case we create an intermediate table:

    • Membership

    Membership represents the relationship between one user, one role and one account.

    We can set up the relationship between all entities and the intermediate table using a OneToMany relationship called ‘memberships’, and optionally, for read only operations we can setup two ManyToMany relationships to the other two tables, called ‘users’, ‘roles’ and ‘accounts’.

    I hope this makes sense.

  2. Log in to comment