Repository navigation
How @updateAt should work when used in relationships
#30954
|
Guys I have read #20323 And AFAIK const chapter = await client.chapter.update({
where: { id: chapterId },
data: {
content: {
upsert: {
create: { content, contentHash },
update: { content, contentHash },
},
},
},
include: { content: true },
});For this schema I learned that the But I am unsure if this is really a bug and if you agree I guess I can open an issue for this as well. |
Replies: 1 comment 1 reply
|
Yeah, this is expected, not a bug. @updatedat gets set on every update() call on a model, so your chapter.update() bumps the chapter's updatedAt even though the only thing in data is the nested content upsert. The content row gets its own new timestamp from the upsert, so both move. If you only want the content timestamp to move, skip the nested write and update the content row directly. Your chapter already holds the content id, so: const { contentId } = await client.chapter.findUniqueOrThrow({
where: { id: chapterId },
select: { contentId: true },
});
const content = await client.chapterContent.upsert({
where: { id: contentId },
create: { content, contentHash },
update: { content, contentHash },
});That leaves chapter.updatedAt alone. Going the other way round doesn't work either, updating a child directly never touches the parent, there's no built-in option for that yet. |
Yeah, this is expected, not a bug. @updatedat gets set on every update() call on a model, so your chapter.update() bumps the chapter's updatedAt even though the only thing in data is the nested content upsert. The content row gets its own new timestamp from the upsert, so both move.
If you only want the content timestamp to move, skip the nested write and update the content row directly. Your chapter already holds the content id, so: