Foreign Key Constraint Behavior in Mendix After Adding New Associations.

0
In Mendix v10.24.0, I initially created an entity Person and associated it with PersonAddress, and everything worked as expected with the Foreign Key constraints enabled at runtime. Later, I disabled the foreign key constraints and added a new entity PersonEmailAddress, also associated with Person. However, when I check the databases, it still shows the same ID values for the associations. Why does this happen, and how does disabling foreign key constraints affect the way Mendix handles and stores associations in the database ?
asked
1 answers
0

Hi Ashish,

 

In Mendix there is no foreign key concept (of course there is no direct foreign key)

Whenever you create an entity, the entity will have one more extra attribute named ID created by Mendix. whenever you create a new object for that entity, it creates one random GUID number and assign it to ID attribute. and this acts as Primary Key for your table.

 

Now if you create an association, it creates one more table. 

So in your scenario in first case It has 3 entities Person, PersonAddress and PersonAddress_Person (name of the Assocation). 

 

so here 3rd table contains only 2 rows, Person_Id and PersonAddress_Id and it stores the GUIDs of respective entities and hence it establishes the association.

So when you delete the Assocation, it actually deletes the table PersonAddress_Person but the GUIDs of Person are still same in Person table.

 

Now if you created one more association to PersonEmailAddress , it creates one more table called PersonEmailAddress_Person and again stores GUIDs of the respective entities. 

Since Person GUIDs are not changed, it uses the same GUIDs of Person here.

 

Hope this is clarified.

 

For more details how this works follow below Docs

https://docs.mendix.com/refguide/associations/

 

answered