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.
103 lines (70 loc) • 2.22 kB
text/typescript
import { Collection, Entity, ManyToOne, MikroORM, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
import { SqliteDriver } from '@mikro-orm/sqlite';
({ tableName: 'brands' })
export class Brand {
()
id!: number;
({ entity: () => BrandSiteRestriction, mappedBy: 'brand' })
brandSiteRestrictions = new Collection<BrandSiteRestriction>(this);
}
({ tableName: 'brand_site_restrictions' })
export class BrandSiteRestriction {
()
id!: number;
({ entity: () => Site })
site!: any;
({ entity: () => Brand })
brand!: Brand;
}
({ tableName: 'placements' })
export class Placement {
()
id!: number;
({ entity: () => Publisher, nullable: true })
publisher?: any;
({ entity: () => Site })
site!: any;
}
({ tableName: 'publishers' })
export class Publisher {
({ entity: () => Site, mappedBy: 'publisher' })
sites = new Collection<Site>(this);
()
id!: number;
}
({ tableName: 'sites' })
export class Site {
({ entity: () => Publisher, nullable: true })
publisher?: Publisher;
({ entity: () => Placement, mappedBy: 'site' })
placements = new Collection<Placement>(this);
({ entity: () => BrandSiteRestriction, mappedBy: 'site' })
brandSiteRestrictions = new Collection<BrandSiteRestriction, Site>(this);
()
id!: number;
({ length: 191, nullable: true })
name?: string;
}
describe('GH issue 1009', () => {
let orm: MikroORM<SqliteDriver>;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [BrandSiteRestriction, Site, Brand, Publisher, Placement],
dbName: `:memory:`,
driver: SqliteDriver,
});
const generator = orm.schema;
await generator.createSchema();
});
afterAll(async () => {
await orm.close(true);
});
it('sets keys from references', async () => {
const site = new Site();
const brand = new Brand();
const br = new BrandSiteRestriction();
br.site = site;
br.brand = brand;
await expect(orm.em.persistAndFlush(br)).resolves.toBeUndefined();
});
});