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.
51 lines (37 loc) • 987 B
text/typescript
import { Embeddable, Embedded, Entity, PrimaryKey, Property } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/better-sqlite';
()
export class Profile {
()
username?: string;
}
()
export class User {
()
id!: number;
()
name!: string;
(() => Profile, { array: true })
profiles: Profile[] = [];
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [User],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(async () => {
await orm.close(true);
});
test('null value instead of object inside embedded property', async () => {
const user = orm.em.create(User, {
name: 'Peter Pan',
profiles: [null as any],
});
await orm.em.insert(user);
expect(user.id).toBeDefined();
const u = await orm.em.fork().findOneOrFail(User, user);
expect(JSON.stringify(u)).toBe('{"id":1,"name":"Peter Pan","profiles":[null]}');
});