Composite Key Support to the DataModel - Mendix Forum

Composite Key Support to the DataModel

5

This is a pretty common use case to have more than one field part of the primary key. I am not sure why this is not supported yet. There are questions about this in the Mendix Forum since last 8 years https://community.mendix.com/link/questions/1652

asked
3 answers

@Bhanu Gandluri, I am expecting a more clear first class support, there are many ways of achieving it. i see your workaround as a good option too. But, this is forum for ideas and not questions. :) The request was to provide First class support for a simple data modeling feature that has been available in most basic RDBMS solutions for ages.

Created

This workaround may have been suggested already but will work best if the keys are String. Create a new unique attribute in the entity you want the composite key.

In your Before Commit Microflow concatenate both keys and store in the attribute. Since this attribute is Unique, you are not going to get duplicates for that foreign key.  Made sense?

Parent Entity(Attribute: Key1)  ChildTable(UniqueAttribute,Key2) – Before commit to ChildTable (UniqueAttribute = key1+key2). This way you are cheating to get a foreign key relationship into the ChildTable.

Created

I completly agree. To sharpen the discussion a little bit:

The Primary key is always a generated column which I presume is used in association as well. So it is not an issue of the primary key because this is modeled in a different way. 

Remains the composite key support which is then in the end a unique constraint on multiple fields. And yes there ought to be first class support for that

Created