Skip to content

@CreateDateColumn and @UpdateDateColumn should use value if provided. #3271

@wederer

Description

@wederer

Issue type:

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

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] 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:
Entity User:

    @PrimaryColumn({
        nullable: false,
        primary: true,
    })
    id: number;

     @CreateDateColumn({
        nullable: false,
        name: "dt_create"
    })
    createdOn: Date;

    @UpdateDateColumn({
        nullable: false,
        name: "dt_modified"
    })
    modifiedOn: Date;

And then run:

    const date = new Date(2017, 11, 24, 12);
    const user = new User();
    user.id = 1;
    user.modifiedOn = date;
    user.createdOn= date;

    getRepository(User).insert(user);
    getRepository(User).update(user);

The behaviour of save, update and insert are pretty strange when it comes the the @CreateDateColumn and @UpdateDateColumn decorators.

When running the above code and a user with the same id is already present following error is thrown:

multiple assignments to same column "dt_modified"

TypeORM is probably adding any @UpdateDateColumn property to update queries which causes this error. I would expect to be able to override the value if needed.

save just ignores the value instead. Values passed in the insert however are used and the outcome is as expected.

Is this behaviour expected/intended or is this a bug?

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