'TypeORM relations in transaction
After reading TypeORM documentation, it is not clear to me, if it is safe to use lazy relations inside transactions. The documentation about transactions says:
All operations MUST be executed using the provided transactional entity manager.
Does it apply for loading related entities as well? When using lazy relations, can I do the following?
await dataSource.transaction(async (transactionalEntityManager) => {
const parentEntity = await transactionalEntityManager.findOneBy(ParentEntity, {
id: 1,
});
const childEntity = await parentEntity.child; // It works, but is it safe?
})
If not, what is the proper way of loading relations inside transactions? Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
