Last active
November 16, 2019 18:20
-
-
Save koskimas/2b66daf34ed47d4a8eba613f07e1c306 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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