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.
53 lines (37 loc) • 955 B
text/typescript
import { Collection, Entity, ManyToOne, MikroORM, OneToMany, PrimaryKey } from '@mikro-orm/postgresql';
()
class A {
({ fieldName: 'prc_id' })
id!: number;
(() => B, b => b.a)
b = new Collection<B>(this);
}
()
class B {
({ fieldName: 'dec_id' })
id!: number;
({ entity: () => A, fieldName: 'prc_id' })
a!: A;
}
describe('GH issue 1990', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [A, B],
dbName: 'mikro_orm_test_1990',
});
await orm.schema.refreshDatabase();
});
afterAll(async () => {
await orm.close(true);
});
test(`GH issue 1990`, async () => {
const a = new A();
const b = new B();
a.b.add(b);
await orm.em.persistAndFlush(a);
orm.em.clear();
const a1 = await orm.em.findOneOrFail(A, a, { populate: ['b'] });
expect(a1.b).toHaveLength(1);
});
});