TGTGamer
TGTGamer
Explore posts from servers
DTDrizzle Team
Created by TGTGamer on 10/22/2024 in #help
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?
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 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
1 replies
DTDrizzle Team
Created by TGTGamer on 10/7/2024 in #help
Many to Many Query With
Pretty simply question. Many to Many relationships have "helper" tables. These simply relate the two tables together. Is there a way to ignore the helper tables in the query output? My current attempts just end up with: TS2353: Object literal may only specify known properties....
const result = yield* Effect.tryPromise(
() => db.query.pos.findFirst( {
where: (
pos,
{ eq }
) => (
eq( pos.id, id )
),
with: {
outlets: {
with: {
outlet: {
with: {
products: {
with: {
product: true
}
}
}
}
}
}
}
}
} )
)
const result = yield* Effect.tryPromise(
() => db.query.pos.findFirst( {
where: (
pos,
{ eq }
) => (
eq( pos.id, id )
),
with: {
outlets: {
with: {
outlet: {
with: {
products: {
with: {
product: true
}
}
}
}
}
}
}
}
} )
)
1 replies