Using results of one query in another

Hello everyone, have a little problem i’m stuck on and wondering if anyone has come across it before.
So I have a .service function that should make a first query, and then in a second query, it should use the results from the first query, something like this:

const authors = db.author.findMany({ where: { ... } })

const posts = db.post.findMany({
  where: {
    author: {
      id: {
        in: authors.map((author) => author.id)
      }
    }
  }
})

However Redwood throws a “Cannot read property ‘call’ of undefined” error when i try to run this query. Is such a query possible with Prisma?

Try explicitly making your service async and then add awaits ahead of the db calls.

Thanks @dthyresson, that did the trick :+1:

1 Like