generator-begcode
Version:
Spring Boot + Angular/React/Vue in one handy generator
25 lines (24 loc) • 1.54 kB
JavaScript
import { addOtherRelationship } from '../../base-application/support/index.js';
import { databaseTypes } from '../../../lib/jhipster/index.js';
const { NO: NO_DATABASE, SQL, NEO4J } = databaseTypes;
export const addEntitiesOtherRelationships = (entities) => {
const result = { warning: [] };
for (const entity of entities.filter(entity => !entity.builtIn)) {
for (const relationship of entity.relationships ?? []) {
if (!relationship.otherRelationship &&
!relationship.otherEntity.embedded &&
(relationship.otherEntityRelationshipName ||
relationship.relationshipType === 'many-to-many' ||
(relationship.relationshipType === 'one-to-one' && entity.databaseType === SQL) ||
(relationship.relationshipType === 'one-to-many' && entity.databaseType !== NEO4J && entity.databaseType !== NO_DATABASE))) {
if (relationship.otherEntity.builtIn) {
result.warning.push(`Ignoring '${entity.name}' definitions as it is using a built-in Entity '${relationship.otherEntityName}': 'otherEntityRelationshipName' is set with value '${relationship.otherEntityRelationshipName}' at relationship '${relationship.relationshipName}' but no back-reference was found`);
}
else {
relationship.otherRelationship = addOtherRelationship(entity, relationship.otherEntity, relationship);
}
}
}
}
return result;
};