Skip to content

Instantly share code, notes, and snippets.

@koskimas
Last active November 16, 2019 18:20
Show Gist options
  • Select an option

  • Save koskimas/2b66daf34ed47d4a8eba613f07e1c306 to your computer and use it in GitHub Desktop.

Select an option

Save koskimas/2b66daf34ed47d4a8eba613f07e1c306 to your computer and use it in GitHub Desktop.
// Note that the following query isn't executed! There's no `await`.
const finnishActorsThatHaveChildren = Actor.query()
.where('nationality', 'finnish')
.whereExists(Actor.relatedQuery('children'))
// This is the only query that gets executed. `finnishActorsThatHaveChildren`
// query is built into the SQL as a subquery.
await Actor.relatedQuery('movies')
.for(finnishActorsThatHaveChildren)
.unrelate()
.where('movies.rating', 'R')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment