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

Transformers do not work for the MongoDB driver #6506

Closed
roderik opened this issue Aug 3, 2020 · 1 comment
Closed

Transformers do not work for the MongoDB driver #6506

roderik opened this issue Aug 3, 2020 · 1 comment

Comments

@roderik
Copy link

roderik commented Aug 3, 2020

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

  @Column('text', {
    transformer: {
      from: (value: string): BigNumber => BigNumber.from(value),
      to: (value: BigNumber): string => value.toString(),
    },
  })
  gasUsed!: BigNumber;

gasUsed is stored in the database as the "object", not as the result of the toString() function

The transformer code is correct because the following works correctly in Mongoose

  @Prop({  
    get: (value: string): BigNumber => BigNumber.from(value),
    set: (value: BigNumber): string => value.toString() 
  })
  gasUsed!: BigNumber;

There was a very old ticket about this mentioning some commented out code, but I could not find it and at first glance, the mongodb driver should execute the transformer code here https://github.com/typeorm/typeorm/blob/master/src/driver/mongodb/MongoDriver.ts#L295-L308 triggered by

value = this.connection.driver.preparePersistentValue(value, column);

@imnotjames
Copy link
Contributor

Duplicate of #4268

@imnotjames imnotjames marked this as a duplicate of #4268 Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants