Skip to content

Commit 69ff7a8

Browse files
committed
Merge remote-tracking branch 'origin/master' into refactor/remove-find-by-ids
# Conflicts: # docs/docs/guides/8-migration-v1.md
2 parents 5daf8d5 + cd4c47b commit 69ff7a8

43 files changed

Lines changed: 21 additions & 3325 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/docs/guides/8-migration-v1.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,24 @@ const UserRepository = dataSource.getRepository(User).extend({
306306

307307
The following error classes were also removed: `CustomRepositoryDoesNotHaveEntityError`, `CustomRepositoryCannotInheritRepositoryError`, `CustomRepositoryNotFoundError`.
308308

309+
### `@RelationCount` decorator and `loadRelationCountAndMap`
310+
311+
The `@RelationCount` decorator and `SelectQueryBuilder.loadRelationCountAndMap()` method have been removed. Use `@VirtualColumn` or a sub-query in your query builder instead:
312+
313+
```typescript
314+
// Before
315+
@RelationCount((post: Post) => post.categories)
316+
categoryCount: number
317+
318+
// After — use @VirtualColumn with a sub-query
319+
// Replace the junction table name and column names to match your schema
320+
@VirtualColumn({
321+
query: (alias) =>
322+
`SELECT COUNT(*) FROM post_categories_category WHERE postId = ${alias}.id`,
323+
})
324+
categoryCount: number
325+
```
326+
309327
## QueryBuilder
310328

311329
### `onConflict`

extra/typeorm-class-transformer-shim.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ exports.OneToMany = OneToMany;
199199
}
200200
exports.OneToOne = OneToOne;
201201

202-
/* export */ function RelationCount(relation) {
203-
return function(object, propertyName) {};
204-
}
205-
exports.RelationCount = RelationCount;
206-
207202
/* export */ function RelationId(relation) {
208203
return function(object, propertyName) {};
209204
}

extra/typeorm-model-shim.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,6 @@ exports.OneToMany = OneToMany;
197197
}
198198
exports.OneToOne = OneToOne;
199199

200-
/* export */ function RelationCount() {
201-
return noop
202-
}
203-
exports.RelationCount = RelationCount;
204-
205200
/* export */ function RelationId() {
206201
return noop
207202
}

src/decorator/relations/RelationCount.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export * from "./decorator/relations/ManyToMany"
4949
export * from "./decorator/relations/ManyToOne"
5050
export * from "./decorator/relations/OneToMany"
5151
export * from "./decorator/relations/OneToOne"
52-
export * from "./decorator/relations/RelationCount"
5352
export * from "./decorator/relations/RelationId"
5453
export * from "./decorator/entity/Entity"
5554
export * from "./decorator/entity/ChildEntity"

src/metadata-args/MetadataArgsStorage.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { RelationMetadataArgs } from "./RelationMetadataArgs"
22
import type { ColumnMetadataArgs } from "./ColumnMetadataArgs"
3-
import type { RelationCountMetadataArgs } from "./RelationCountMetadataArgs"
43
import type { IndexMetadataArgs } from "./IndexMetadataArgs"
54
import type { EntityListenerMetadataArgs } from "./EntityListenerMetadataArgs"
65
import type { TableMetadataArgs } from "./TableMetadataArgs"
@@ -49,7 +48,6 @@ export class MetadataArgsStorage {
4948
readonly joinColumns: JoinColumnMetadataArgs[] = []
5049
readonly joinTables: JoinTableMetadataArgs[] = []
5150
readonly entityListeners: EntityListenerMetadataArgs[] = []
52-
readonly relationCounts: RelationCountMetadataArgs[] = []
5351
readonly relationIds: RelationIdMetadataArgs[] = []
5452
readonly embeddeds: EmbeddedMetadataArgs[] = []
5553
readonly inheritances: InheritanceMetadataArgs[] = []
@@ -132,19 +130,6 @@ export class MetadataArgsStorage {
132130
)
133131
}
134132

135-
filterRelationCounts(target: Function | string): RelationCountMetadataArgs[]
136-
filterRelationCounts(
137-
target: (Function | string)[],
138-
): RelationCountMetadataArgs[]
139-
filterRelationCounts(
140-
target: (Function | string) | (Function | string)[],
141-
): RelationCountMetadataArgs[] {
142-
return this.filterByTargetAndWithoutDuplicateProperties(
143-
this.relationCounts,
144-
target,
145-
)
146-
}
147-
148133
filterIndices(target: Function | string): IndexMetadataArgs[]
149134
filterIndices(target: (Function | string)[]): IndexMetadataArgs[]
150135
filterIndices(

src/metadata-args/RelationCountMetadataArgs.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/metadata-builder/EntityMetadataBuilder.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { EmbeddedMetadata } from "../metadata/EmbeddedMetadata"
66
import type { MetadataArgsStorage } from "../metadata-args/MetadataArgsStorage"
77
import type { EmbeddedMetadataArgs } from "../metadata-args/EmbeddedMetadataArgs"
88
import { RelationIdMetadata } from "../metadata/RelationIdMetadata"
9-
import { RelationCountMetadata } from "../metadata/RelationCountMetadata"
109
import { EventListenerTypes } from "../metadata/types/EventListenerTypes"
1110
import { MetadataUtils } from "./MetadataUtils"
1211
import type { TableMetadataArgs } from "../metadata-args/TableMetadataArgs"
@@ -749,18 +748,6 @@ export class EntityMetadataBuilder {
749748

750749
return new RelationIdMetadata({ entityMetadata, args })
751750
})
752-
entityMetadata.relationCounts = this.metadataArgsStorage
753-
.filterRelationCounts(entityMetadata.inheritanceTree)
754-
.map((args) => {
755-
// for single table children we reuse relation counts created for their parents
756-
if (entityMetadata.tableType === "entity-child")
757-
return entityMetadata.parentEntityMetadata.relationCounts.find(
758-
(relationCount) =>
759-
relationCount.propertyName === args.propertyName,
760-
)!
761-
762-
return new RelationCountMetadata({ entityMetadata, args })
763-
})
764751
entityMetadata.ownListeners = this.metadataArgsStorage
765752
.filterListeners(entityMetadata.inheritanceTree)
766753
.map((args) => {
@@ -917,11 +904,6 @@ export class EntityMetadataBuilder {
917904
.map((args) => {
918905
return new RelationIdMetadata({ entityMetadata, args })
919906
})
920-
embeddedMetadata.relationCounts = this.metadataArgsStorage
921-
.filterRelationCounts(targets)
922-
.map((args) => {
923-
return new RelationCountMetadata({ entityMetadata, args })
924-
})
925907
embeddedMetadata.embeddeds = this.createEmbeddedsRecursively(
926908
entityMetadata,
927909
this.metadataArgsStorage.filterEmbeddeds(targets),
@@ -1099,16 +1081,10 @@ export class EntityMetadataBuilder {
10991081
)
11001082
entityMetadata.propertiesMap = entityMetadata.createPropertiesMap()
11011083
entityMetadata.relationIds.forEach((relationId) => relationId.build())
1102-
entityMetadata.relationCounts.forEach((relationCount) =>
1103-
relationCount.build(),
1104-
)
11051084
entityMetadata.embeddeds.forEach((embedded) => {
11061085
embedded.relationIdsFromTree.forEach((relationId) =>
11071086
relationId.build(),
11081087
)
1109-
embedded.relationCountsFromTree.forEach((relationCount) =>
1110-
relationCount.build(),
1111-
)
11121088
})
11131089
}
11141090

src/metadata-builder/EntityMetadataValidator.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ export class EntityMetadataValidator {
117117
)
118118
}
119119

120-
entityMetadata.relationCounts.forEach((relationCount) => {
121-
if (
122-
relationCount.relation.isManyToOne ||
123-
relationCount.relation.isOneToOne
124-
)
125-
throw new TypeORMError(
126-
`Relation count can not be implemented on ManyToOne or OneToOne relations.`,
127-
)
128-
})
129-
130120
if (!(driver.options.type === "mongodb")) {
131121
entityMetadata.columns
132122
.filter((column) => !column.isVirtualProperty)

src/metadata/EmbeddedMetadata.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { RelationMetadata } from "./RelationMetadata"
33
import type { EntityMetadata } from "./EntityMetadata"
44
import type { EmbeddedMetadataArgs } from "../metadata-args/EmbeddedMetadataArgs"
55
import type { RelationIdMetadata } from "./RelationIdMetadata"
6-
import type { RelationCountMetadata } from "./RelationCountMetadata"
76
import type { DataSource as dataSource } from "../data-source/DataSource"
87
import type { EntityListenerMetadata } from "./EntityListenerMetadata"
98
import type { IndexMetadata } from "./IndexMetadata"
@@ -75,11 +74,6 @@ export class EmbeddedMetadata {
7574
*/
7675
relationIds: RelationIdMetadata[] = []
7776

78-
/**
79-
* Relation counts inside this embed.
80-
*/
81-
relationCounts: RelationCountMetadata[] = []
82-
8377
/**
8478
* Nested embeddable in this embeddable (which has current embedded as parent embedded).
8579
*/
@@ -167,11 +161,6 @@ export class EmbeddedMetadata {
167161
*/
168162
relationIdsFromTree: RelationIdMetadata[] = []
169163

170-
/**
171-
* Relation counts of this embed and all relation counts from its child embeds.
172-
*/
173-
relationCountsFromTree: RelationCountMetadata[] = []
174-
175164
// ---------------------------------------------------------------------
176165
// Constructor
177166
// ---------------------------------------------------------------------
@@ -225,8 +214,6 @@ export class EmbeddedMetadata {
225214
this.indicesFromTree = this.buildIndicesFromTree()
226215
this.uniquesFromTree = this.buildUniquesFromTree()
227216
this.relationIdsFromTree = this.buildRelationIdsFromTree()
228-
this.relationCountsFromTree = this.buildRelationCountsFromTree()
229-
230217
if (connection.options.entitySkipConstructor) {
231218
this.isAlwaysUsingConstructor =
232219
!connection.options.entitySkipConstructor
@@ -344,12 +331,4 @@ export class EmbeddedMetadata {
344331
this.relationIds,
345332
)
346333
}
347-
348-
protected buildRelationCountsFromTree(): RelationCountMetadata[] {
349-
return this.embeddeds.reduce(
350-
(relations, embedded) =>
351-
relations.concat(embedded.buildRelationCountsFromTree()),
352-
this.relationCounts,
353-
)
354-
}
355334
}

0 commit comments

Comments
 (0)