title: Is there a way that I can access saved entities within a transaction in TypeORM?
body: <p>I'm using Nest.js with TypeORM and Postgres.</p>
  <p>What I'm trying to do is create and instance of my <code>User</code> entity. It has <code>Membership</code> and <code>File</code> fields that are also entities. Those has One to One relationship with <code>User</code>, so are created when <code>User</code> is created. If anything goes wrong I want to rollback everything, therefore I'm using a transaction.</p>
  <p>This is what I'm doing:</p>
  <pre class="lang-js prettyprint-override"><code>async create(userProcessed: UserProcessed): Promise&lt;UserResponse&gt; {
      const response: UserResponse = {
        message: 'User not created',
        success: false,
        user: undefined,
      };
      const queryRunner = this.connection.createQueryRunner();
      await queryRunner.connect();
      await queryRunner.startTransaction();
      try {
        const membership = new Membership();
        membership.membershipState = userProcessed.membershipState;
        membership.membershipType = userProcessed.membershipType;
        const membershipSaved = await queryRunner.manager.save(membership);
        if (!membershipSaved) throw Error();
  
        const file = new File();
        file.weight = userProcessed.file.weight;
        file.height = userProcessed.file.height;
        const fileSaved = await queryRunner.manager.save(file);
        if (!fileSaved) throw Error(response.message);
  
        const user = new User();
        user.email = userProcessed.email;
        user.firstName = userProcessed.firstName;
        user.lastName = userProcessed.lastName;
        user.gender = userProcessed.gender;
        user.file = fileSaved;
        user.membership = membershipSaved;
        user.role = userProcessed.role;
        user.birthday = new Date(userProcessed.birthday);
        user.setPassword(userProcessed.password);
  
        const userSaved = await this.userRepository.save(user);
        console.log(userSaved);
        if (!userSaved) throw Error(response.message);
  
        response.success = true;
        response.message = 'User created';
        response.user = userSaved;
  
        await queryRunner.commitTransaction();
        return response;
      } catch (e) {
        await queryRunner.rollbackTransaction();
        throw Error(response.message);
      } finally {
        await queryRunner.release();
      }
    }
  </code></pre>
  <p>The problem comes when user is created. As I'm using an transaction, nothing is saved into the DB until I call <code>await queryRunner.commitTransaction();</code> (as it has to be). As result, the <code>membership</code> and <code>file</code> that I'm trying to use as foreign key doesn't really exists.</p>
  <p>Is there a way that I can solve this in the same transaction?</p>