Update returning with some relation

As the title says I am updating an object using this syntax:
const idToUpdate = "someId";
const newEvent = {...};
// event table has one-to-one relationship with table cost
const updatedEvent = await db.update(eventTable).set(newEvent).where(eq(eventTable.id, idToUpdate)).returning();

return updatedEvent;
const idToUpdate = "someId";
const newEvent = {...};
// event table has one-to-one relationship with table cost
const updatedEvent = await db.update(eventTable).set(newEvent).where(eq(eventTable.id, idToUpdate)).returning();

return updatedEvent;
is it possible for returning to return the update object with some relation, or would I need to fetch the object from the database in a separate query?
// something like this
const idToUpdate = "someId";
const newEvent = {...};
await db.update(eventTable).set(newEvent).where(eq(eventTable.id, idToUpdate));

// fetch the updated eventTable entry afterwards with it's cost relation
return await db.query.eventTable.findFirst({where: eq(eventTable.id, idToUpdate), with: {cost: true}});
// something like this
const idToUpdate = "someId";
const newEvent = {...};
await db.update(eventTable).set(newEvent).where(eq(eventTable.id, idToUpdate));

// fetch the updated eventTable entry afterwards with it's cost relation
return await db.query.eventTable.findFirst({where: eq(eventTable.id, idToUpdate), with: {cost: true}});
1 Reply
nqhtrung
nqhtrung2w ago
I believe your question is answered here https://www.answeroverflow.com/m/1177544395306827826 As far as I’m concerned, it’s not possible in Postgres (assumed that’s what you’re using). If it can’t be done via native query, it’s not possible in Drizzle
insert returning relations - Drizzle Team
Hello, is it possible to have the relations included in the returned row using insert().returning()? Or do I have to make a separate query for that?

Did you find this page helpful?