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

RelationId() on nullable relation returns 'null' string #6815

Closed
angel200sdnot opened this issue Sep 30, 2020 · 0 comments · Fixed by #6848
Closed

RelationId() on nullable relation returns 'null' string #6815

angel200sdnot opened this issue Sep 30, 2020 · 0 comments · Fixed by #6848

Comments

@angel200sdnot
Copy link

Issue type:

[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.25 (or put your version here)

Steps to reproduce or a small repository showing the problem:

@Entity()
export class ChildEntity {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: string;
}

@Entity()
export class ParentEntity {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: string;

  @OneToOne(() => ChildEntity, { nullable: true })
  @JoinColumn()
  child: ChildEntity | null;

  @RelationId((parent: ParentEntity) => parent.child)
  childId: string | null;
}

const parent = await entityManager.getRepository(ParentEntity).findOne(parentId);
console.log(parent) // parent.childId will be 'null' if column is null in database

Expected behaviour

childId should be null instead of 'null'

Additional comments

I am getting around this issue by using Column() instead of RelationId()

anttimaki added a commit to anttimaki/typeorm that referenced this issue Oct 4, 2020
Fix issue where attempting to cast bigints to strings also did it for
null values.

Fix issue where transformRelationIds() filtered out null values when
it should only be done for undefined.

Closes: typeorm#6815
pleerock pushed a commit that referenced this issue Oct 5, 2020
Fix issue where attempting to cast bigints to strings also did it for
null values.

Fix issue where transformRelationIds() filtered out null values when
it should only be done for undefined.

Closes: #6815
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
Fix issue where attempting to cast bigints to strings also did it for
null values.

Fix issue where transformRelationIds() filtered out null values when
it should only be done for undefined.

Closes: typeorm#6815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants