I need help with Mendix Model SDK and Mendix Platform SDK

0
Hello everyone, I am using the mendix platform sdk and mendix model sdk to generate a mendix app from an excel file (the database part only). I need help with relationships between entities. In the code I was only able to create a 1-N relationship, but I would like to be able to also do 1-1 and N-N. Can anyone help me?
asked
2 answers
3
const entity1 = domainmodels.Entity.createIn(domainModel);
    entity1.name = `NewEntity1_${Date.now()}`;

    const entity2 = domainmodels.Entity.createIn(domainModel);
    entity2.name = `NewEntity2_${Date.now()}`;

    const association1to1 = domainmodels.Association.createIn(domainModel);
    association1to1.name = entity2.name + "_" + entity1.name;
    association1to1.parent = entity1;
    association1to1.child = entity2;
    association1to1.type = domainmodels.AssociationType.Reference
    association1to1.owner = domainmodels.AssociationOwner.Both;

image.png

answered
2

for one to one you can use 

 

const association1to1 = domainmodels.Association.createIn(workingCopy.model);
association1to1.parent = entity1;
association1to1.child = entity2;
association1to1.type = domainmodels.AssociationType.Reference;

 

For N to N, you need to create 2 association 1-N,

 

const intermediateEntity = domainmodels.Entity.createIn(workingCopy.model);

// First 1-N association
const associationNtoIntermediate = domainmodels.Association.createIn(workingCopy.model);
associationNtoIntermediate.parent = entity1;
associationNtoIntermediate.child = intermediateEntity;
associationNtoIntermediate.type = domainmodels.AssociationType.ReferenceSet;

// Second 1-N association
const associationIntermediateToN = domainmodels.Association.createIn(workingCopy.model);
associationIntermediateToN.parent = intermediateEntity;
associationIntermediateToN.child = entity2;
associationIntermediateToN.type = domainmodels.AssociationType.ReferenceSet;

 

answered