Open naorye opened 3 years ago
me too 👍
@naorye @Jane-Tran Hello all, I solved the problem by writing the proper setting for the Nestjs TypeOrmModule when using Custom Repositories, please see the line of imports in the code below:
@Module({
providers: [UsersService],
imports: [TypeOrmModule.forFeature([UsersRepository])],
exports: [UsersService],
controllers: [UsersController],
})
export class UsersModule {}
The "Custom Repository" must be provided to when calling .forFeature()
Hope this helps!!!
Hi all, I had the same problem and it turned out I was missing one thing, so this is an example of a service I had before adding typeorm-transactional-cls-hooked
:
@Injectable()
export class MyEntityService {
constructor(
@InjectRepository(MyEntity)
private readonly repository: Repository<MyEntity>,
) {}
...
}
So after adding typeorm-transactional-cls-hooked
it got changed to
@Injectable()
export class MyEntityService {
constructor(
@InjectRepository(MyEntity)
private readonly repository: MyEntityRepository, // <--------------------------------- CHANGED HERE
) {}
...
}
But what I missed was that I forgot to delete @InjectRepository(MyEntity)
, so the final working code looks like this:
@Injectable()
export class MyEntityService {
constructor(
// <--------------------------------- CHANGED HERE
private readonly repository: MyEntityRepository,
) {}
...
}
I am using nestjs with typeorm and recentrly I added transaction support with typeorm-transactional-cls-hooked. I made the following method:
connectionsRepository
is defined like that:When I am calling
updateConnection
, I end up withconnection.name
equals to111
even though the transaction was rejected. What I am missing?