Skip to content

Commit

Permalink
adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Nov 23, 2023
1 parent 02b8fb8 commit 058a76a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions generators/base-application/support/prepare-relationship.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default function prepareRelationship(entityWithConfig, relationship, gene
const entityName = entityWithConfig.name;
const otherEntityName = relationship.otherEntityName;
const jhiTablePrefix = entityWithConfig.jhiTablePrefix || hibernateSnakeCase(entityWithConfig.jhiPrefix);
const databaseType = entityWithConfig.databaseType;

if (!relationship.otherEntity) {
throw new Error(
Expand Down Expand Up @@ -77,8 +76,7 @@ export default function prepareRelationship(entityWithConfig, relationship, gene
// means that this side should control the reference.
ownerSide: ({ ownerSide, relationshipLeftSide, relationshipManyToOne, relationshipOneToMany }) =>
ownerSide ?? (relationshipManyToOne || (relationshipLeftSide && !relationshipOneToMany)),
persistableRelationship: ({ persistableRelationship, ownerSide, relationshipManyToMany }) =>
persistableRelationship ?? (databaseType === 'neo4j' || ownerSide || relationshipManyToMany),
persistableRelationship: ({ persistableRelationship, ownerSide }) => persistableRelationship ?? ownerSide,
relationshipUpdateBackReference: ({ relationshipUpdateBackReference, ownerSide, relationshipRightSide }) =>
relationshipUpdateBackReference ?? (entityWithConfig.databaseType === 'neo4j' ? relationshipRightSide : !ownerSide),
});
Expand Down
17 changes: 17 additions & 0 deletions generators/spring-data-relational/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ export default class SqlGenerator extends BaseApplicationGenerator<SpringBootGen
return this.delegateTasksToBlueprint(() => this.preparing);
}

get preparingEachEntity() {
return this.asPreparingEachEntityTaskGroup({
prepareEntity({ entity }) {
entity.relationships.forEach(relationship => {
if (relationship.persistableRelationship === undefined) {
// This is a v8.1 behavior, make it default if blueprints adopts it.
relationship.persistableRelationship = relationship.ownerSide || relationship.relationshipManyToMany;
}
});
},
});
}

get [BaseApplicationGenerator.PREPARING_EACH_ENTITY]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntity);
}

get preparingEachEntityRelationship() {
return this.asPreparingEachEntityRelationshipTaskGroup({
prepareRelationship({ application, relationship }) {
Expand Down

0 comments on commit 058a76a

Please sign in to comment.