UNPKG

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.

64 lines (46 loc) 1.26 kB
import { v4 } from 'uuid'; import { Collection, Entity, ManyToMany, MikroORM, PrimaryKey, Property } from '@mikro-orm/sqlite'; @Entity() export class A { @PrimaryKey() uuid: string = v4(); @Property() name!: string; @ManyToMany(() => B, b => b.aCollection) bCollection = new Collection<B>(this); } @Entity() export class B { @PrimaryKey() uuid: string = v4(); @Property() name!: string; @ManyToMany(() => A, undefined, { fixedOrder: true }) aCollection = new Collection<A>(this); } describe('GH issue 268', () => { let orm: MikroORM; beforeAll(async () => { orm = await MikroORM.init({ entities: [A, B], dbName: ':memory:', }); await orm.schema.dropSchema(); await orm.schema.createSchema(); }); afterAll(() => orm.close(true)); test('m:n with uuid PKs', async () => { const a1 = new A(); a1.name = 'a1'; const a2 = new A(); a2.name = 'a2'; const a3 = new A(); a3.name = 'a3'; const b = new B(); b.name = 'b'; b.aCollection.add(a1, a2, a3); await orm.em.persistAndFlush(b); const res = await orm.em.getConnection().execute('select * from b_a_collection'); expect(res[0]).toEqual({ id: 1, a_uuid: a1.uuid, b_uuid: b.uuid }); }); });