DT
Drizzle Team•2mo ago
chico

findMany not including right table details in query

the question details exceeded the post word limit github discussion link
https://github.com/drizzle-team/drizzle-orm/discussions/2702
GitHub
findMany not including right table details in query · drizzle-team ...
here is the schema definition export const authorsTable = sqliteTable('authors', {<columns>...}) export const booksTable = sqliteTable('books', {<columns>...}) export co...
2 Replies
rphlmr âš¡
rphlmr ⚡•2mo ago
👋 in chapters and books, you also need to use with
result = db.query.authorsTable.findMany({
with: {
chapters: {
books: true // error
},
books: {
chapters: true // error
},
},
})
result = db.query.authorsTable.findMany({
with: {
chapters: {
books: true // error
},
books: {
chapters: true // error
},
},
})
result = db.query.authorsTable.findMany({
with: {
chapters: {
with: {
books: true
}
},
books: {
with: {chapters: true}
},
},
})
result = db.query.authorsTable.findMany({
with: {
chapters: {
with: {
books: true
}
},
books: {
with: {chapters: true}
},
},
})
chico
chico•2mo ago
@Raphaël M (@rphlmr) ⚡ thanks for your reply when I use with nested, I get an error
Object literal may only specify known properties, and 'books' does not exist in type '{ author?: true | { columns?: { id?: boolean; ... }; with?: { books?: true | DBQueryConfig<"many", false, ExtractTablesWithRelations<typeof import(../db/src/schema/index")>, { ...; }>;
Object literal may only specify known properties, and 'books' does not exist in type '{ author?: true | { columns?: { id?: boolean; ... }; with?: { books?: true | DBQueryConfig<"many", false, ExtractTablesWithRelations<typeof import(../db/src/schema/index")>, { ...; }>;
and
'Object literal may only specify known properties, and chapters' does not exist in type '{ author?: true | {...}`
'Object literal may only specify known properties, and chapters' does not exist in type '{ author?: true | {...}`
i changed it a little and this one gives the expected result
result = db.query.authorsTable.findMany({
with: {
chapters: {
with: {
chapter: true,
},
},
books: {
with: { book: true },
},
},
})
result = db.query.authorsTable.findMany({
with: {
chapters: {
with: {
chapter: true,
},
},
books: {
with: { book: true },
},
},
})
thanks @Raphaël M (@rphlmr) ⚡ ✨
Want results from more Discord servers?
Add your server