Created
February 26, 2019 19:39
-
-
Save B4nan/d572179c3fa2edcc6e0bdee60f57d5c7 to your computer and use it in GitHub Desktop.
Working with collections in MikroORM
This file contains 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 author and populate his books collection | |
const author = orm.em.findOne(Author, '...', ['books']); | |
for (const book of author.books) { | |
console.log(book); // instance of Book | |
} | |
author.books.add(book); | |
console.log(author.books.contains(book)); // true | |
author.books.remove(book); | |
console.log(author.books.contains(book)); // false | |
author.books.add(book); | |
console.log(author.books.count()); // 1 | |
console.log(author.books.getItems()); // Book[] | |
console.log(author.books.getIdentifiers()); // array of primary keys of all items | |
author.books.removeAll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment