Skip to content

Commit

Permalink
expose relationshipsByOtherEntity property
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Apr 20, 2023
1 parent 8bb32ee commit 035b835
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 9 additions & 7 deletions generators/base-application/support/prepare-entity.mts
Original file line number Diff line number Diff line change
Expand Up @@ -540,18 +540,20 @@ function preparePostEntityCommonDerivedPropertiesNotTyped(entity: any) {
entity.anyPropertyHasValidation =
entity.anyPropertyHasValidation || relationships.some(({ relationshipValidate }) => relationshipValidate);

const relationshipsByType = relationships
const relationshipsByOtherEntity = relationships
.filter(rel => !rel.otherEntity.embedded)
.map(relationship => [relationship.otherEntity.entityNameCapitalized, relationship])
.reduce((relationshipsByType: any, [type, relationship]) => {
if (!relationshipsByType[type]) {
relationshipsByType[type] = [relationship];
.reduce((relationshipsByOtherEntity: any, [type, relationship]) => {
if (!relationshipsByOtherEntity[type]) {
relationshipsByOtherEntity[type] = [relationship];
} else {
relationshipsByType[type].push(relationship);
relationshipsByOtherEntity[type].push(relationship);
}
return relationshipsByType;
return relationshipsByOtherEntity;
}, {});

entity.differentRelationships = relationshipsByType;
entity.relationshipsByOtherEntity = relationshipsByOtherEntity;
entity.differentRelationships = relationshipsByOtherEntity;

entity.anyPropertyHasValidation = entity.anyPropertyHasValidation || fields.some(({ fieldValidate }) => fieldValidate);

Expand Down
3 changes: 3 additions & 0 deletions generators/bootstrap-application/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ describe(`generator - ${generator}`, () => {
"readOnly": false,
"regularEagerRelations": Any<Array>,
"relationships": [],
"relationshipsByOtherEntity": {},
"relationshipsContainEagerLoad": false,
"relationshipsContainOtherSideIgnore": false,
"requiresPersistableImplementation": false,
Expand Down Expand Up @@ -845,6 +846,7 @@ describe(`generator - ${generator}`, () => {
"readOnly": false,
"regularEagerRelations": Any<Array>,
"relationships": [],
"relationshipsByOtherEntity": {},
"relationshipsContainEagerLoad": false,
"relationshipsContainOtherSideIgnore": false,
"requiresPersistableImplementation": false,
Expand Down Expand Up @@ -1156,6 +1158,7 @@ describe(`generator - ${generator}`, () => {
"readOnly": false,
"regularEagerRelations": Any<Array>,
"relationships": [],
"relationshipsByOtherEntity": {},
"relationshipsContainEagerLoad": false,
"relationshipsContainOtherSideIgnore": false,
"requiresPersistableImplementation": false,
Expand Down

0 comments on commit 035b835

Please sign in to comment.