Subqueries in relational queries

I'd like to use the query API but combine the where with a subquery. Meaning get all posts where the author's name is "John".

I understand I can use the select syntax, but would prefer the ORM approach if possible:


await db.query.posts.findMany({
  // assuming `posts` has an ID field:
  where: (fields, ops) => ops.eq(fields.id, **SOME SORT OF SUBQUERY HERE**)
  with: {
    author: true,
  },
});


I haven't seen any mention of it but seems doable with a subquery, any suggestions?
Was this page helpful?