diff --git a/lib/entitiescreator.js b/lib/entitiescreator.js index ff2184c..67c55f7 100644 --- a/lib/entitiescreator.js +++ b/lib/entitiescreator.js @@ -289,13 +289,18 @@ function extractField(field) { } function setRelationshipOfEntity(classId) { - var associations = getRelatedAssociations( + var relatedAssociations = getRelatedAssociations( classId, parsedData.associations); - for (let i = 0; i < associations.from.length; i++) { + setSourceAssociationsForClass(relatedAssociations, classId); + setDestinationAssociationsForClass(relatedAssociations, classId); +} + +function setSourceAssociationsForClass(relatedAssociations, classId) { + for (let i = 0; i < relatedAssociations.from.length; i++) { let otherSplitField; let splitField; - let association = parsedData.getAssociation(associations.from[i]); + let association = parsedData.getAssociation(relatedAssociations.from[i]); checkValidityOfAssociation( association, parsedData.getClass(association.from).name, @@ -342,10 +347,13 @@ function setRelationshipOfEntity(classId) { } entities[classId].relationships.push(relationship); } - for (let i = 0; i < associations.to.length; i++) { +} + +function setDestinationAssociationsForClass(relatedAssociations, classId) { + for (let i = 0; i < relatedAssociations.to.length; i++) { let splitField; let otherSplitField; - let association = parsedData.getAssociation(associations.to[i]); + let association = parsedData.getAssociation(relatedAssociations.to[i]); let relationship = { relationshipType: (association.type === cardinalities.ONE_TO_MANY ? cardinalities.MANY_TO_ONE : association.type) };