Where based on relationships?
I'm trying to query the database for a specific values which fit a filter based on relationships. Is this possible?
In the above example I got the
const result = yield* Effect.tryPromise(
() => db.query.productUniqueId.findMany(
{
// ...options,
where:
(
productUniqueId,
{ and, eq }
) => (
and(
eq( productUniqueId.type, type ),
eq( productUniqueId.product.outlets.outlet.id, outletId),
)
),
with: {
product: {
columns: {},
with: {
outlets: {
columns: {},
with: {
outlet: {
columns: {
id: true,
name: true
}
}
}
}
}
}
}
}
)
)const result = yield* Effect.tryPromise(
() => db.query.productUniqueId.findMany(
{
// ...options,
where:
(
productUniqueId,
{ and, eq }
) => (
and(
eq( productUniqueId.type, type ),
eq( productUniqueId.product.outlets.outlet.id, outletId),
)
),
with: {
product: {
columns: {},
with: {
outlets: {
columns: {},
with: {
outlet: {
columns: {
id: true,
name: true
}
}
}
}
}
}
}
}
)
)In the above example I got the
TS2551: Property product does not exist on typeTS2551: Property product does not exist on type - so I switched to filtering after getting the data from the database, but wanted to see if there was a way to handle this in the query