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.

59 lines (41 loc) 1.06 kB
import { Collection, Entity, ManyToMany, MikroORM, PrimaryKey, Property } from '@mikro-orm/sqlite'; @Entity() class A { @PrimaryKey() id!: number; @Property() test1!: string; @ManyToMany({ entity: () => B, mappedBy: 'a' }) b = new Collection<B>(this); } @Entity() class B { @PrimaryKey() id!: number; @Property() test2!: string; @Property() test3!: string; @ManyToMany({ entity: () => A, inversedBy: 'b' }) a = new Collection<A>(this); } let orm: MikroORM; beforeAll(async () => { orm = await MikroORM.init({ entities: [A, B], dbName: ':memory:', }); await orm.schema.refreshDatabase(); }); afterAll(() => orm.close()); test('loadItems with fields (#4464)', async () => { const a = orm.em.create(A, { test1: 'yxcv', b: [ { test2: 'qwer', test3: 'asdf' }, ] }); await orm.em.flush(); orm.em.clear(); await orm.em.findOne(B, 1, { fields: ['test2'] }); const a2 = await orm.em.findOneOrFail(A, 1); const test3 = (await a2.b.loadItems())[0].test3; expect(test3).toMatch('asdf'); });