UNPKG

undeexcepturi

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

19 lines (14 loc) 797 B
--- title: Entity References --- Every single entity relation is mapped to an entity reference. Reference is an entity that has only its identifier. This reference is stored in identity map so you will get the same object reference when fetching the same document from database. You can call `await entity.init()` to initialize the entity. This will trigger database call and populate itself, keeping the same reference in identity map. ```typescript const author = orm.em.getReference('...id...'); console.log(author.id); // accessing the id will not trigger any db call console.log(author.isInitialized()); // false console.log(author.name); // undefined await author.init(); // this will trigger db call console.log(author.isInitialized()); // true console.log(author.name); // defined ```