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 29, 2021
1 parent 074024a commit 6e9c5e0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion generators/entity-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = class extends BaseBlueprintGenerator {
},

useMapsIdRelation() {
const jpaDerivedRelation = this.relationships.find(rel => rel.id === true);
const jpaDerivedRelation = this.relationships.find(rel => rel.id && rel.relationshipType === 'one-to-one');
if (jpaDerivedRelation) {
this.isUsingMapsId = true;
this.mapsIdAssoc = jpaDerivedRelation;
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
4 changes: 3 additions & 1 deletion utils/relationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function prepareRelationshipForTemplates(entityWithConfig, relationship, generat
}

relationship.relatedField = otherEntityData.fields.find(field => field.fieldName === relationship.otherEntityField);
if (!relationship.relatedField && !relationship.otherEntity.embedded) {
if (!relationship.relatedField && !relationship.otherEntity.embedded && !relationship.otherEntity.primaryKey.composite) {
if (otherEntityData.primaryKey && otherEntityData.primaryKey.derived) {
Object.defineProperty(relationship, 'relatedField', {
get() {
Expand Down Expand Up @@ -147,6 +147,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 6e9c5e0

Please sign in to comment.