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
text/typescript
import { Collection, Entity, ManyToMany, MikroORM, PrimaryKey, Property } from '@mikro-orm/sqlite';
()
class A {
()
id!: number;
()
test1!: string;
({ entity: () => B, mappedBy: 'a' })
b = new Collection<B>(this);
}
()
class B {
()
id!: number;
()
test2!: string;
()
test3!: string;
({ 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');
});