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.
64 lines (45 loc) • 1.23 kB
text/typescript
import { Entity, Ref, ManyToOne, MikroORM, PrimaryKey, Reference } from '@mikro-orm/postgresql';
()
export class First {
()
id!: number;
}
()
export class Second {
()
id!: number;
}
()
export class Third {
({ primary: true, entity: () => First, ref: true })
first: Ref<First>;
({ primary: true, entity: () => Second, ref: true })
second: Ref<Second>;
constructor(first: First, second: Second) {
this.first = Reference.create(first);
this.second = Reference.create(second);
}
}
describe('GH issue 2148', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [First, Second, Third],
dbName: 'mikro_orm_test_2148',
});
await orm.schema.refreshDatabase();
});
afterAll(() => orm.close(true));
test('persisting composite PK entity with reference wrapper', async () => {
const a = new First();
const b = new Second();
const c = new Third(a, b);
await orm.em.persistAndFlush(c);
orm.em.clear();
const cc = await orm.em.findOneOrFail(Third, {
first: a.id,
second: b.id,
});
await orm.em.remove(cc).flush();
});
});