Embedded createdAt field is not updated
garrensmith opened this issue · comments
If I have a model like this:
export class Comment {
@Field()
content: string;
@Field()
name: string;
@Field({ timestamp: "createdAt" })
createdAt?: Date;
}
@TigrisCollection("post")
export class Post {
@PrimaryKey(TigrisDataTypes.UUID, { order: 1, autoGenerate: true })
id?: string;
@Field({ timestamp: "createdAt" })
createdAt?: Date;
@Field({ timestamp: "updatedAt" })
updatedAt?: Date;
@Field()
title: string;
@Field()
content?: string;
@Field({ default: false })
published?: boolean;
@Field(TigrisDataTypes.ARRAY, { elements: Comment })
comments: Array<Comment>;
}
And then I run this:
await setup();
const db = await tigrisClient.getDatabase();
const postCollection = await db.getCollection<Post>(Post);
const post = await postCollection.insertOne({
title: "A book review of Designing Data-Intensive Applications",
content: `
Design Data-intensive Applications by Martin Kleppmann is a must read
for anyone that loves learning about databases and build distributed systems.
It covers a large range of topics on the complexity of building distributed systems.
It is one of my favourite technical books.
`,
comments: [],
});
post.comments.push({
content:
"Thank you for the excellent book review. I've added it to my reading list",
name: "Henry",
});
post.comments.push({
content:
"I strongly disagree, everyone should be learning distributed systems from reading academic papers only!",
name: "Angry Max",
});
const updated = await postCollection.insertOrReplaceOne(post);
console.log(updated.comments);
In the bottom line when I console log the comments
the createdAt
field is undefined. We don't seem to be processing the embedded array and adding the default fields.
A duplicate of tigrisdata-archive/tigris-client-ts#245