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/6dda9783f442da93ef86e9f9c8b2d9bc to your computer and use it in GitHub Desktop.

Select an option

Save B4nan/6dda9783f442da93ef86e9f9c8b2d9bc to your computer and use it in GitHub Desktop.
Usage of Identity Map in MikroORM
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