Skip to content

@UpdateDateColumn updates the column value without precision #2718

@d-yokoi

Description

@d-yokoi

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

  • Create an entity class which has a column decorated with @UpdateDateColumn
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';

@Entity('sample')
export class Sample {
  @PrimaryGeneratedColumn({ name: 'id', unsigned: true })
  id?: string;

  @Column('varchar', { name: 'name' })
  name: string;

  @CreateDateColumn({ name: 'created_at', precision: 3 })
  readonly createdAt?: Date;

  @UpdateDateColumn({ name: 'updated_at', precision: 3 })
  readonly updatedAt?: Date;
}
  • Create an entity object and insert to the database
  • Find the same entity object, modify some columns and update with the save method
  • The column with @UpdateDateColumn is updated with CURRENT_TIMESTAMP without precision

I think it would work if it uses MySQL's ON UPDATE like ON UPDATE CURRENT_TIMESTAMP(3).
But the wrong expression is hard coded below.
https://github.com/typeorm/typeorm/blob/master/src/query-builder/UpdateQueryBuilder.ts#L417

Is there any workaround ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions