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.
47 lines (33 loc) • 954 B
text/typescript
import { Entity, MikroORM, OneToOne, PrimaryKey } from '@mikro-orm/sqlite';
()
export class B {
({ entity: 'A', joinColumn: 'id', primary: true, mapToPk: true })
id!: number;
}
()
export class A {
()
id!: number;
({ entity: 'B', mappedBy: 'id' })
entity!: B;
}
describe('GH issue 1124', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [A, B],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(() => orm.close(true));
test('According to docs we can use mapToPk option on M:1 and 1:1 relations and it does not work for 1:1', async () => {
const a = new A();
await orm.em.persistAndFlush(a);
a.entity = new B();
await orm.em.flush();
orm.em.clear();
const entity = await orm.em.findOneOrFail(A, { id: 1 });
expect(entity.entity).toMatchObject({ id: 1 });
});
});