I am inserting date in my database with a defined createAt date. I don’t want to use now() as default in postgres. So I have create my column as such using typeorm.
@Field(() => DateTimeScalar)
@Column("timestamp without time zone",{})
createdAt: Date;
and when I am inserting in my database I am creating a date as such:
Date("2022-05-08 00:49:23").toIsoString()
and then create an object as such Interaction.create({createdAt: createdDate})
, I later add this interaction to my array of interactions and save them:
await getConnection().getRepository(Interaction).save(interactions)
The createdAt value is always overwritten with the current date, I even checked postgres and I can confirm there is no now() as default for this column.
Any ideas how do I disable this autogen option?
2
Answers
You can use
@CreateDateColumn
decorator. linkType ORM will do all the stuff for you. You don’t need to set it, just leave this field alone.
As I wrote in comment, I had a very similar issue. Reported in on Github (https://github.com/typeorm/typeorm/issues/9966), but eventually solved it myself.
The reason for the problem I had was that my build command was not emptying out dist folder and thus I had older files sitting in it, which Typeorm (by my design) was automatically loading and using.
So check if you have or had any subscribers, which are automatically loading and thus rewriting your data in the middle of calls.