Johnny
Johnny
DTDrizzle Team
Created by Johnny on 12/16/2024 in #help
Filter on included relations
Hello! Hope you're all doing well! Is it possible to filter based on included relations?
return await this.db.query.myTable.findMany({
with: {
relations: true,
},
where: (doc, { and, eq, inArray }) => {
const predicates: SQL[] = [];
predicates.push(
eq(schema.relationTable.type, "my-type"),
);
predicates.push(
eq(schema.relationTable.value, value.toString()),
);

return predicates.length > 0 ? and(...predicates) : undefined;
},
});
return await this.db.query.myTable.findMany({
with: {
relations: true,
},
where: (doc, { and, eq, inArray }) => {
const predicates: SQL[] = [];
predicates.push(
eq(schema.relationTable.type, "my-type"),
);
predicates.push(
eq(schema.relationTable.value, value.toString()),
);

return predicates.length > 0 ? and(...predicates) : undefined;
},
});
4 replies