Skip to content

Commit

Permalink
eager load relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Oct 20, 2023
1 parent 1d71a17 commit 8546748
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions generators/base-application/support/prepare-entity.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ import pluralize from 'pluralize';

import type BaseGenerator from '../../base-core/index.mjs';
import { getDatabaseTypeData, hibernateSnakeCase } from '../../server/support/index.mjs';
import { createFaker, parseChangelog, stringHashCode, upperFirstCamelCase, getMicroserviceAppName } from '../../base/support/index.mjs';
import {
createFaker,
parseChangelog,
stringHashCode,
upperFirstCamelCase,
getMicroserviceAppName,
mutateData,
} from '../../base/support/index.mjs';
import { fieldToReference } from './prepare-field.mjs';
import { getTypescriptKeyType, getEntityParentPathAddition } from '../../client/support/index.mjs';
import {
Expand Down Expand Up @@ -616,14 +623,15 @@ function preparePostEntityCommonDerivedPropertiesNotTyped(entity: any) {
relationship.relationshipEagerLoad = false;
return;
}
relationship.bagRelationship = relationship.ownerSide && relationship.collection;
if (relationship.relationshipEagerLoad === undefined) {
relationship.relationshipEagerLoad =

mutateData(relationship, {
bagRelationship: relationship.collection,
relationshipEagerLoad: () =>
relationship.bagRelationship ||
entity.eagerLoad ||
// Fetch relationships if otherEntityField differs otherwise the id is enough
(relationship.ownerSide && relationship.otherEntity.primaryKey.name !== relationship.otherEntityField);
}
relationship.otherEntity.primaryKey.name !== relationship.otherEntityField,
});
});
entity.relationshipsContainEagerLoad = entity.relationships.some(relationship => relationship.relationshipEagerLoad);
entity.containsBagRelationships = entity.relationships.some(relationship => relationship.bagRelationship);
Expand Down

0 comments on commit 8546748

Please sign in to comment.