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.
85 lines (60 loc) • 2.05 kB
text/typescript
import { Embeddable, Embedded, Entity, MikroORM, OneToOne, PrimaryKey, Property, Rel } from '@mikro-orm/sqlite';
class LoopOptions {
'enabled-prop': boolean = false;
'type-prop': string = 'a';
}
class Options {
'loop-prop' = new LoopOptions();
}
class PlayerEntity {
id!: number;
'options-prop' = new Options();
test: string = 'abc';
'parent-case-property'?: Rel<ParentEntity>;
}
class ParentEntity {
id!: number;
'kebab-case-property': PlayerEntity;
}
describe('GH issue 1958', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [PlayerEntity, Options, LoopOptions],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(async () => {
await orm.close();
});
test(`GH issue 1958`, async () => {
const e = new PlayerEntity();
e['parent-case-property'] = new ParentEntity();
expect(e['options-prop']).toBeInstanceOf(Options);
expect(e['options-prop']['loop-prop']).toBeInstanceOf(LoopOptions);
expect(e['options-prop']['loop-prop']['enabled-prop']).toBe(false);
expect(e['options-prop']['loop-prop']['type-prop']).toBe('a');
await orm.em.persistAndFlush(e);
orm.em.clear();
const e1 = await orm.em.findOneOrFail(PlayerEntity, e);
expect(e1['options-prop']).toBeInstanceOf(Options);
expect(e1['options-prop']['loop-prop']).toBeInstanceOf(LoopOptions);
expect(e1['options-prop']['loop-prop']['enabled-prop']).toBe(false);
expect(e1['options-prop']['loop-prop']['type-prop']).toBe('a');
expect(e1['parent-case-property']).toBeInstanceOf(ParentEntity);
});
});