Jeno
Jeno
DTDrizzle Team
Created by Jeno on 9/20/2024 in #help
In a relation subquery, how to reference parent column?
I have this query:
const result = await db.query.author.findFirst({
where: (author) => eq(author.slug, params.slug),
with: {
collections: {
with: {
collection: {
with: {
books: {
with: {
book: {
with: {
authors: {
where: (authorBook, { ne }) => ne(authorBook.authorId, author.id),
with: {
author: true
}
}
}
}
}
},
authors: {
with: {
author: true
}
}
}
}
}
}
}
});
const result = await db.query.author.findFirst({
where: (author) => eq(author.slug, params.slug),
with: {
collections: {
with: {
collection: {
with: {
books: {
with: {
book: {
with: {
authors: {
where: (authorBook, { ne }) => ne(authorBook.authorId, author.id),
with: {
author: true
}
}
}
}
}
},
authors: {
with: {
author: true
}
}
}
}
}
}
}
});
Basically I want to query an author, with collections, and collections have books, books can have multiple authors. I want to query only other book authors where they are not the main author. The query doesn't error out but it includes the main author on every book. What am I missing?
4 replies