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.14 kB
text/typescript
import { Entity, MikroORM, OneToOne, PrimaryKey, Property } from '@mikro-orm/sqlite';
()
export class A {
()
id!: number;
()
name!: string;
({ entity: () => B, nullable: true, orphanRemoval: true })
b?: any;
}
()
export class B {
()
id!: number;
()
name!: string;
(() => A, a => a.b, { nullable: true })
a?: A;
}
describe('GH issue 2806', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [A, B],
dbName: ':memory:',
});
await orm.schema.refreshDatabase();
});
afterAll(() => orm.close(true));
test('search by m:n', async () => {
const a = orm.em.create(A, { name: 'a', b: { name: 'b' } });
await orm.em.fork().persistAndFlush(a);
orm.em.clear();
const a1 = await orm.em.findOneOrFail(A, a, { populate: ['b'] });
a1.b = orm.em.create(B, { name: 'b2' });
await orm.em.flush();
expect(a1.b).toBeDefined();
const a2 = await orm.em.fork().findOneOrFail(A, a, { populate: ['b'] });
expect(a2.b).toBeDefined();
});
});