Last active
April 30, 2019 16:24
-
-
Save B4nan/6dda9783f442da93ef86e9f9c8b2d9bc to your computer and use it in GitHub Desktop.
Usage of Identity Map 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
| const authorRepository = orm.em.getRepository(Author); | |
| const jon = await authorRepository.findOne({ name: 'Jon Snow' }, ['books']); | |
| const jon2 = await authorRepository.findOne({ email: '[email protected]' }); | |
| const authors = await authorRepository.findAll(['books']); | |
| // identity map in action | |
| console.log(jon === authors[0]); // true | |
| console.log(jon === jon2); // true | |
| // as we always have one instance, books will be populated also here | |
| console.log(jon2.books); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment