expeditavoluptas
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.
50 lines (35 loc) • 1.12 kB
text/typescript
import { Entity, Enum, ManyToOne, MikroORM, PrimaryKey } from '@mikro-orm/core';
import { PostgreSqlDriver } from '@mikro-orm/postgresql';
export enum BrandType {
Foo = 'foo',
Bar = 'bar',
Baz = 'baz'
}
({ tableName: 'brand' })
export class Brand {
({ primary: true, items: () => BrandType })
id!: BrandType;
}
({ tableName: 'product' })
export class Product {
()
id!: number;
(() => Brand)
brand!: Brand;
}
describe('using enum as a foreign key value', () => {
test('schema generator creates the correct type', async () => {
const orm = await MikroORM.init({
entities: [Brand, Product],
dbName: `mikro_orm_test_enum_foreign_key`,
driver: PostgreSqlDriver,
});
await orm.schema.ensureDatabase();
await orm.schema.execute('drop table if exists brand cascade');
await orm.schema.execute('drop table if exists product cascade');
const diff = await orm.schema.getUpdateSchemaSQL({ wrap: false });
expect(diff).toMatchSnapshot();
await orm.schema.execute(diff);
await orm.close(true);
});
});