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.
73 lines (52 loc) • 1.23 kB
text/typescript
import { Entity, PrimaryKey, Property, MikroORM, wrap, ManyToOne } from '@mikro-orm/postgresql';
()
class A {
()
id!: number;
({ nullable: true })
foo?: string;
}
()
class B {
()
id!: number;
({ nullable: true })
foo?: string;
}
()
class C {
()
id!: number;
()
a: A;
()
b: B;
constructor(a: A, b: B) {
this.a = a;
this.b = b;
}
}
describe('GH issue 533', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [A, B, C],
dbName: `mikro_orm_test_gh_533`,
});
await orm.schema.refreshDatabase();
});
afterAll(async () => {
await orm.close(true);
});
test(`select by string PK instead of number`, async () => {
const a = new A();
const b = new B();
const c = new C(a, b);
await orm.em.persistAndFlush(c);
orm.em.clear();
// we need to get around TS compiler here via `any`
const c1 = await orm.em.findOneOrFail(C, { a: '' + a.id } as any, { populate: ['a'] });
expect(wrap(c1.a).isInitialized()).toBe(true);
expect(wrap(c1.b).isInitialized()).toBe(false);
});
});