one-to-one relations with query, use joined table in where

I have something like this:
export const thingUsers = sqliteTable(...)
export const users = sqliteTable(...)

export const thingUsersRelations = relations(thingUsers, ({ one, many }) => ({
user: one(users, {
fields: [thingUsers.userId],
references: [users.id],
relationName: "user",
}),
thing: one(thing, {
fields: [thingUsers.thingId],
references: [thing.id],
relationName: "thingUser",
}),
}));

await db.query.thingUsers
.findMany({
with: {
user: true,
thing: true,
},
where: eq($.thing.publicId, publicThingId),
});
export const thingUsers = sqliteTable(...)
export const users = sqliteTable(...)

export const thingUsersRelations = relations(thingUsers, ({ one, many }) => ({
user: one(users, {
fields: [thingUsers.userId],
references: [users.id],
relationName: "user",
}),
thing: one(thing, {
fields: [thingUsers.thingId],
references: [thing.id],
relationName: "thingUser",
}),
}));

await db.query.thingUsers
.findMany({
with: {
user: true,
thing: true,
},
where: eq($.thing.publicId, publicThingId),
});
Which obviously doesn't work, because thing is not joined but is instead "requested" via a subquery in the select clause. Is there any plan on implementing this feature or I should just rely on the query builder? Thanks.
0 Replies
No replies yetBe the first to reply to this messageJoin