I want to save without affecting UpdateDateColumn when updating view column.
This table is a post table and the view is a hit.
@Entity("post")
export default class Post extends BaseEntity {
@PrimaryGeneratedColumn()
idx: number;
// Skip
@Column({
nullable: false,
default: 0
})
view: number;
@Column("timestampz")
@CreateDateColumn()
created_at: Date;
@Column("timestampz")
@UpdateDateColumn()
updated_at: Date;
}
Give me a solution please.
Not a perfect solution, but still a solution...
You can force update your date column with the value it has:
getRepository(Post).update(postId, {
view: newViewValue,
updated_at: () => '"updated_at"'
})
The SQL-query will look like:
UPDATE "post" SET "view" = $2, "updated_at" = "updated_at" WHERE "idx" = $1