Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for TypeORM 0.3 #1549

Open
abidon opened this issue Aug 16, 2022 · 3 comments
Open

Support for TypeORM 0.3 #1549

abidon opened this issue Aug 16, 2022 · 3 comments

Comments

@abidon
Copy link

abidon commented Aug 16, 2022

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today we used patch-package to patch @nestjs-query/query-typeorm@0.30.0 for the project we are working on. This patch made our codebase work with TypeORM 0.3.


Apparently, with TypeORM 0.3, this.repo.manager.getRepository(relationMeta.type).target return a string instead of the entity class in some cases.

// (1) in TodoEntity.ts
@ManyToOne(() => ProjectEntity)
project: ProjectEntity;

// (2) in ProjectEntity.ts
@OneToMany('TodoEntity', (todo) => todo.project
todos: TodoEntity[]
  1. When specifying a typeFunction, repository.target equals the ProjectEntity class
  2. 鈿狅笍 When specifying a string, repository.target is the 'TodoEntity' string, not class

This behaviour was introduced in TypeORM 0.3 and breaks nestjs-query, while TypeORM 0.2 always returned the entity class (at least in our use cases).


Here is the diff that solved our problem:

diff --git a/node_modules/@nestjs-query/query-typeorm/dist/src/services/relation-query.service.js b/node_modules/@nestjs-query/query-typeorm/dist/src/services/relation-query.service.js
index 0d46f16..8d06fee 100644
--- a/node_modules/@nestjs-query/query-typeorm/dist/src/services/relation-query.service.js
+++ b/node_modules/@nestjs-query/query-typeorm/dist/src/services/relation-query.service.js
@@ -245,7 +245,7 @@ class RelationQueryService {
     getRelationEntity(relationName) {
         const relationMeta = this.getRelationMeta(relationName);
         if (typeof relationMeta.type === 'string') {
-            return this.repo.manager.getRepository(relationMeta.type).target;
+            return this.repo.manager.connection.entityMetadatas.find(em => em.targetName == relationMeta.type).target;
         }
         return relationMeta.type;
     }

This issue body was partially generated by patch-package.

@TriPSs
Copy link

TriPSs commented Aug 28, 2022

TypeORM v3 support is now released in the alpha version of my fork together with all the fixes from here

@henry-huynh-3508
Copy link

TypeORM v3 support is now released in the alpha version of my fork together with all the fixes from here

Thanks TriPSs for keeping fixing the project bugs. The project owner should have transferred things over if he no longer continues to maintain this project, what a shame that it's a good project.

@dzcpy
Copy link

dzcpy commented Nov 16, 2022

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants