Skip to content

Instantly share code, notes, and snippets.

@B4nan
Last active April 30, 2019 16:24
Show Gist options
  • Select an option

  • Save B4nan/3a91aa966fd2e58c3cdf690a66446e27 to your computer and use it in GitHub Desktop.

Select an option

Save B4nan/3a91aa966fd2e58c3cdf690a66446e27 to your computer and use it in GitHub Desktop.
Fetching entities in MikroORM
// 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