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.
55 lines (39 loc) • 1.04 kB
text/typescript
import { Embeddable, Embedded, Entity, MikroORM, PrimaryKey, Property } from '@mikro-orm/sqlite';
()
export class Lock {
()
createdAt: Date = new Date();
}
()
export class File {
()
id!: number;
(() => Lock, {
nullable: true,
object: true, // error only throws with object mode
})
lock?: Lock;
}
describe('GH issue 2233', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Lock, File],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(() => orm.close(true));
test('cascade persist with pre-filled PK and with cycles', async () => {
const file = new File();
await orm.em.fork().persistAndFlush(file);
const [raw] = await orm.em
.createQueryBuilder(File)
.select('*')
.where({ id: file.id })
.limit(1)
.getKnexQuery();
const mapped = orm.em.map(File, raw);
expect(mapped).toEqual({ id: 1, lock: null });
});
});