chris_st
DTDrizzle Team
•Created by chris_st on 10/19/2024 in #help
Problem with findMany with many-to-many relations
Finally, the output:
entriesFound is [
{
"Id": 2,
"PersonId": 1,
"Content": "Another entry with a tagmarker in it.",
"Timestamp": "2024-10-19T19:30:11.173Z",
"EntriesTags": [
{
"EntryId": 2,
"TagId": 1
}
]
},
{
"Id": 1,
"PersonId": 1,
"Content": "This is a new entry with tags in it.",
"Timestamp": "2024-10-19T19:30:03.568Z",
"EntriesTags": [
{
"EntryId": 1,
"TagId": 1
},
{
"EntryId": 1,
"TagId": 2
},
{
"EntryId": 1,
"TagId": 4
}
]
}
]
Which is really not what I want at all. I want the content of the tags, not the EntryId/TagId pairs. I'm following the https://orm.drizzle.team/docs/rqb#many-to-many many-to-many documentation as closely as I can; I think the
with
part should be:
with: {
Tags: true,
},
But that fails with an error:
ERR main getEntriesForPerson got error TypeError: Cannot read properties of undefined (reading 'referencedTable')
Any help very much appreciated!3 replies
DTDrizzle Team
•Created by chris_st on 10/19/2024 in #help
Problem with findMany with many-to-many relations
Second, here's how I'm querying it:
export const getEntriesForPerson = async (
context: LocalContext,
personId: number
): Promise<EntryList | string> => {
try {
const entriesFound = await getEntriesDb(
context
).query.Entries.findMany({
with: {
EntriesTags: true,
},
where: eq(schema.Entries.PersonId, personId),
limit: 20,
orderBy: [desc(schema.Entries.Timestamp)],
})
console.log(
entriesFound is ${JSON.stringify(entriesFound, null, 2)})
return ok({ entries: entriesFound })
} catch (error: any) {
logTapeLogger.error(
getEntriesForPerson got error ${error.toString()})
return err(error.toString())
}
}
3 replies
DTDrizzle Team
•Created by chris_st on 10/15/2024 in #help
Help with 'in' queries
For anyone else who finds this, trying to deal with this, evidently the
inArray
operator allows this type of query: https://orm.drizzle.team/docs/operators#inarray2 replies