Skip to content

Commit

Permalink
fix: small fixes needed for composite key
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhouti committed Mar 30, 2021
1 parent 074024a commit eb33679
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions generators/entity-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ module.exports = class extends BaseBlueprintGenerator {
},

useMapsIdRelation() {
const jpaDerivedRelation = this.relationships.find(rel => rel.id === true);
if (jpaDerivedRelation) {
if (this.primaryKey && this.primaryKey.derived) {
this.isUsingMapsId = true;
this.mapsIdAssoc = jpaDerivedRelation;
this.mapsIdAssoc = this.relationships.find(rel => rel.id);
this.hasOauthUser = this.mapsIdAssoc.otherEntityName === 'user' && this.authenticationType === 'oauth2';
} else {
this.isUsingMapsId = false;
Expand Down
2 changes: 2 additions & 0 deletions utils/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function prepareFieldForTemplates(entityWithConfig, field, generator) {
fieldNameHumanized: _.startCase(field.fieldName),
fieldTranslationKey: `${entityWithConfig.i18nKeyPrefix}.${field.fieldName}`,
tsType: generator.getTypescriptKeyType(field.fieldType),
entity: entityWithConfig,
});
const fieldType = field.fieldType;
if (field.mapstructExpression) {
Expand Down Expand Up @@ -298,6 +299,7 @@ function prepareFieldForTemplates(entityWithConfig, field, generator) {
}
return data;
};
field.path = [field.fieldName];
field.reference = fieldToReference(entityWithConfig, field);

return field;
Expand Down
18 changes: 8 additions & 10 deletions utils/relationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,12 @@ function prepareRelationshipForTemplates(entityWithConfig, relationship, generat
}

relationship.relatedField = otherEntityData.fields.find(field => field.fieldName === relationship.otherEntityField);
if (!relationship.relatedField && !relationship.otherEntity.embedded) {
if (otherEntityData.primaryKey && otherEntityData.primaryKey.derived) {
Object.defineProperty(relationship, 'relatedField', {
get() {
return otherEntityData.primaryKey.derivedFields.find(field => field.fieldName === relationship.otherEntityField);
},
});
} else if (!ignoreMissingRequiredRelationship) {
throw new Error(`Error looking for field ${relationship.otherEntityField} at ${otherEntityData.name}`);
}
if (!relationship.relatedField && otherEntityData.primaryKey && otherEntityData.primaryKey.derived) {
Object.defineProperty(relationship, 'relatedField', {
get() {
return otherEntityData.primaryKey.derivedFields.find(field => field.fieldName === relationship.otherEntityField);
},
});
}
if (relationship.relatedField) {
relationship.otherEntityFieldCapitalized = relationship.relatedField.fieldNameCapitalized;
Expand All @@ -147,6 +143,8 @@ function prepareRelationshipForTemplates(entityWithConfig, relationship, generat
relationshipNameCapitalized: _.upperFirst(relationshipName),
relationshipNameHumanized: _.startCase(relationshipName),
columnName: generator.getColumnName(relationshipName),
columnNamePrefix:
relationship.id && relationship.relationshipType === 'one-to-one' ? '' : `${generator.getColumnName(relationshipName)}_`,
otherEntityNamePlural: pluralize(otherEntityName),
otherEntityNameCapitalized: _.upperFirst(otherEntityName),
otherEntityTableName:
Expand Down

0 comments on commit eb33679

Please sign in to comment.