Many to Many Relationship - Data Model

Hi, quite new to Mendix and still learning...! I have an Incident entity and a Service entity, and any Incident can relate to many Services, and any Service can relate to Many incidents so want to have a Many to Many relationship.  Traditionally I'd have a Incident_Service entity with the ID's from each table in it.  Am I right in assuming that in Mendix I don't need this and just create a Many to Many relationship between the two entities?   If anybody can point me in the direction of a sample project that implements many to many relationships I'd be really grateful. Cheers Cliff
2 answers

Hello Cliff,

  You are correct that you don't technically need the Incident_Service entity to have a many-to-many relationship.  The Mendix platform will handle the underlying linking tables for you and you just need to specify the association as many-to-many.

  However, it can be helpful at times to have that intermediate transactional data entity.  For example, if you wanted to store some details like when the association was made and what the severity level was, you might want to consider having that intermediate entity with a many-to-one association to both Service and Incident.

  For an example of many-to-many and transactional data, check out the TELCO field service sample app on the app store here:

 In this sample app, you can see many-to-many relationships implemented between the 'Item' and 'Installation' entities.  One installation can use multiple Items and Items can be used at many installations.  Check it out!




Cliff, you're exactly right. Mendix will generate a table called YourModule$Incident_Service with the related IDs in it. You only need to create the many-to-many association in your domain model.

On your pages, you can use the Reference Set selector widget, or a number of widgets from the app store to allow users to set this association (search for "reference" or "tag"). You can of course also set these associations in microflows.