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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enableUuidHack required for query relations to load when relation keys are uuids #131

Open
calvin-cdev opened this issue Feb 22, 2022 · 0 comments

Comments

@calvin-cdev
Copy link
Contributor

Package versions and database engine type (please complete the following information):

  • Database Engine: postgres
  • TypeORM Version: 0.2.41
  • Driver Version: 2.3.5

Describe the bug
When you have a repository query that uses the relation option to load related entities where the relation relies on a uuid field, the query will fail unless enableUuidHack is set to true

You'll get

BadRequestException: ERROR: operator does not exist: uuid = character varying

Presumably because the ids on the relations are not casted a uuid

To Reproduce

@Entity()
export default class A {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  name: string

  @Column()
  bId: string;

  @ManyToOne(() => B)
  @JoinColumn({ name: 'bId' })
  b: B;
}

@Entity()
export default class B {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @OneToMany(() => A, a => a.b)
  a: Array<A>;
}

// create connection without passing `formatOptions` (i.e. enableUuidHack is false)
createConnection({
    type: 'aurora-data-api-pg',
    database: '...',
    secretArn:'...',
    region: '...',
    entities: [
      A,
      B
    ],
  });

// A custom repo
@EntityRepository(A)
export class ARepository extends Repository<A> {
  findByName(
    name: A['name'],
  ): Promise<A | undefined> {
    return this.findOne({
      where: { name },
      relations: ['b'],
    });
  }
}


// use the repo method, it will fail with 
// BadRequestException: ERROR: operator does not exist: uuid = character varying
const result = await getCustomRepository(ARepository).findByName('a name')
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

1 participant