Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: small fixes needed for composite key #14493

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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