Last active
April 30, 2019 16:24
-
-
Save B4nan/3a91aa966fd2e58c3cdf690a66446e27 to your computer and use it in GitHub Desktop.
Fetching entities in MikroORM
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
| // find all authors with name matching 'Jon', and populate all of their books | |
| const authors = await orm.em.find(Author, { name: /Jon/ }, ['books']); | |
| for (const author of authors) { | |
| console.log(author.name); // Jon Snow | |
| for (const book of author.books) { | |
| console.log(book.title); // initialized | |
| console.log(book.author.isInitialized()); // true | |
| console.log(book.author.id); | |
| console.log(book.author.name); // Jon Snow | |
| console.log(book.publisher); // just reference | |
| console.log(book.publisher.isInitialized()); // false | |
| console.log(book.publisher.id); | |
| console.log(book.publisher.name); // undefined | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment