Key ID in API

0
Hi,   I designed an API in Mendix. I have Author and AuthorCitationIndex (ACI) entities. There's a one-to-many relationship between the two entities. This means an Author object can be associated with multiple ACI objects. When creating an Author object, I open a pop-up page on the Author page and create the ACI objects from there. Then, I can see these ACI objects in Data Grid 2 inside the Author object (using association as the source).   When developing the API, I didn't use a separate ACI entity in the message definition and export mapping sections. I opened the association to the API based on the Author entity. However, the team managing the data warehouse wants the data returned from the service to come as separate entities, not joined. That's why they need the key ID; otherwise, they can't perform any operations.   My question is: how do I create the key ID / primary key in my API? Do I keep the id of the ACI object in an attribute of Author object? And when I establish an association between multiple ACI objects and an Author, how can I keep multiple IDs in this attribute? Or vice versa, should I keep the key of the Author object in an attribute when creating the ACI?
asked
1 answers
0

Hi AYBERK AKBALIK

 

You should not put multiple ACI IDs into an Author attribute. Instead, expose the Author key in each ACI record when you design your API message definition. This way, the data warehouse team can treat Author and ACI as separate entities and join them by key. simiply 

  • Keep the primary key of each entity within that entity.

  • Use associations to link them, not attributes holding multiple IDs.

 

Correct design pattern

  • Author entity

    • Attributes: AuthorID (primary key), Name, etc.

    • Association: 1‑* to ACI

  • AuthorCitationIndex entity

    • Attributes: ACIID (primary key), CitationCount, Year, etc.

    • Association: *‑1 to Author (store AuthorID as foreign key in the API mapping)

Sample

{  "AuthorID": "2000",  "Name": "Guru",  "ACIs": [    {      "ACIID": "456",      "CitationCount": 20,      "Year": 2022,      "AuthorID": "123"    },    {      "ACIID": "789",      "CitationCount": 15,      "Year": 2023,      "AuthorID": "123"    }  ]}

 

I hope this helps you

answered