Typescript not showing where field in query. Query working but ts throwing error

Hi, I have a query like below
const weight = await drizzle(c.env.DB, { schema }).query.weights.findFirst({
with: {
type: {
// @ts-expect-error where is not defined in the type
where: and(eq(types.type, parse.type), eq(types.id, parse.type_id)),
// Only showing columns, extras, with field
},
},
where: and(eq(weights.type_id, parse.type_id), eq(weights.weight, parse.weight)),
});
const weight = await drizzle(c.env.DB, { schema }).query.weights.findFirst({
with: {
type: {
// @ts-expect-error where is not defined in the type
where: and(eq(types.type, parse.type), eq(types.id, parse.type_id)),
// Only showing columns, extras, with field
},
},
where: and(eq(weights.type_id, parse.type_id), eq(weights.weight, parse.weight)),
});
// relations.ts
export const typesRelations = relations(types, ({ many }) => ({
weights: many(weights),
}));

export const weightsRelations = relations(weights, ({ one }) => ({
type: one(types, {
fields: [weights.type_id],
references: [types.id],
}),
}));
export const typesRelations = relations(types, ({ many }) => ({
weights: many(weights),
}));

export const weightsRelations = relations(weights, ({ one }) => ({
type: one(types, {
fields: [weights.type_id],
references: [types.id],
}),
}));
I'm using drizzle-orm: ^0.29.1
2 Replies
Angelelz
Angelelz12mo ago
the where is not available in a one relation. If you are filtering a one relation, you might as well not include it. Just remember that this filter is being applied to the related field type, not to the weights
doble_boyler
doble_boyler12mo ago
i have same question, if i have relation table one to many, which is i wan to findFirst [tblA] where related [tblB].otherField = "123". assume [tblA].field relations to [tblB].field
Want results from more Discord servers?
Add your server