How to make a REST Service / Enpoint for Associaton of two Entities

0
Hello All,Im working on a Mendix App, where the Domain Model looks like this:I want to Import a bunch of Data from an external Source via REST Api.Published REST Services are already available for most of the Entities in the Domain Model:The Problem is, that the REST Enpoint does not expose the Field Component_Testrig that represents the 1:N Association between the two Entities.I would like to either expose this Field (if it even exits, i dont know how Mendix Models 1:N relations internally) or expose a seperate Endpoint where I can give two Primary Keys (One for Testrig, and one for Component) which then handles the creation of the association.
asked
2 answers
0

Hi Eric,


As per my understanding of your requirement,

you want to create one component object which also have children object testrig

and

you want to retrieve one component object with it's children object of testrig,

Right?

The simple solution is to update the import and export mapping to include the children(testrig) entity.
I believe you are using messageDefination then it's much easier, you just need to add the testring enity in the messagedefination of component entity.


After the update of import/export mapping you are good to go to for Get/Post operations.

Hope it helps 🙂

answered
0

Hi Eric,

There are a few ways to achieve this.


If you're using a recent Mendix version, you can expose the association directly in your Published REST Service by including the associated object in your published schema.


Alternatively, I'd recommend using OData if your primary goal is to consume the data, as it handles associations and navigation between entities much more naturally than standard REST services.


Also, if you're using the newer Direct Associations feature, the parent ID is stored in the child table as a foreign key, making it much easier to expose and work with these relationships.


Could you let us know which Mendix version you're using? The available options differ slightly between versions.


Kindly mark this as the accepted answer if it helps.

answered