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.
74 lines (52 loc) • 1.43 kB
text/typescript
import { Collection, Entity, ManyToOne, MikroORM, OneToMany, OneToOne, PrimaryKey } from '@mikro-orm/core';
import type { AbstractSqlDriver } from '@mikro-orm/knex';
import { v4 } from 'uuid';
import { SqliteDriver } from '@mikro-orm/sqlite';
()
export class D {
()
id: string = v4();
({ entity: 'A' })
a!: any;
}
()
export class C {
()
id: string = v4();
}
()
export class B {
()
id: string = v4();
}
()
export class A {
({ entity: 'B', joinColumn: 'id', primary: true })
id!: B;
({ entity: 'C', primary: true })
c!: C;
({ entity: 'D', mappedBy: 'a', eager: true })
d = new Collection<D>(this);
}
describe('GH issue 1157', () => {
let orm: MikroORM<AbstractSqlDriver>;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [A, B, C, D],
dbName: ':memory:',
driver: SqliteDriver,
});
await orm.schema.createSchema();
});
afterAll(() => orm.close(true));
test('searching by composite key relation', async () => {
const c = orm.em.create(C, {});
const b = orm.em.create(B, {});
const a = orm.em.create(A, { id: b, c });
const d = orm.em.create(D, { a });
await orm.em.persistAndFlush(d);
orm.em.clear();
const d1 = await orm.em.findOneOrFail(D, { a });
expect(d1.a.id).toBeInstanceOf(B);
});
});