With the release of Direct Associations in Mendix, developers now have a powerful new option for modeling associations that offers clear benefits in terms of performance, database storage, and domain model simplicity. Traditionally, Mendix stores associations in separate join tables, which has worked well for flexibility but can become a performance bottleneck in large-scale applications. Direct Associations change this by allowing associations to be stored as foreign keys directly in the database tables, just like native relational modeling.
Performance: Reduces join operations, resulting in faster queries, especially when retrieving large datasets or deeply nested associations.
Storage: Eliminates intermediary association tables, reducing database complexity and storage overhead.
Simplicity: Domain models more closely reflect the underlying database structure, improving clarity for developers and database admins.
To measure the impact, we created a simple test case: 1 Employee with 100,000 associated Assets.
We compared the traditional association table model with the new Direct Associations in three key areas: database structure, SQL complexity, and performance.
This visual comparison shows how much leaner and more intuitive the database becomes when using direct foreign keys instead of separate association tables. It reduces schema complexity and improves maintainability, particularly as your app scales. Developers and DBAs alike benefit from having a one-to-one match between the Mendix domain model and the physical data model.
The SQL generated for traditional association tables often involves additional joins through an intermediate table. This increases query complexity and can slow down performance, especially with large datasets.
With Direct Associations, the generated SQL is cleaner and more efficient. The join is simplified to a direct foreign key reference. This kind of query is easier for the database engine to optimize, leading to better runtime performance and faster responses.
In our test case, retrieving 100,000 assets through a traditional association table took significantly longer. The join on the association table adds overhead. This can accumulate in real-world apps with many users or frequent access to large data sets.
When the Asset object owns the association, retrieval is slightly more efficient—but still slower compared to Direct Associations. The join remains necessary. While owner-side retrieval is generally faster, it's not a substitute for the optimization offered by direct foreign keys.
While 1-1 associations have been problematic for quite some time, let's take a look at how direct associations handle this:
Direct Associations simplify 1-1 relationships significantly as the foreign key only lives in 1 table, however does this have an impact on the dirty state issue of 1-1 associations? More on this in a later blog…
While switching to Direct Associations is usually beneficial, changing the association type means that the DDL (Data Definition Language) will be rewritten in the database. This can trigger long migration times if your existing tables contain a lot of rows.
Also note that Direct Associations are not available for *-* associations.
Additionally Mendix suggests to not use direct associations yet in modules which are designed to be imported into apps (for example, Marketplace modules) as this could cause unexpected migrations in an app the module is being imported into. For this blog we have not tested this.
Direct Associations represent a major step forward in how Mendix apps interact with their underlying databases. If you're dealing with high volumes of data or complex models, it's worth revisiting your associations and considering whether a migration to Direct Associations could simplify your architecture and speed up your app.
Want to try it out?
Read more in the official documentation and let us know how it impacts your app’s performance!
Irena Dzambo & Adnan Calpin-Ramlawi