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.
103 lines (78 loc) • 1.72 kB
text/typescript
import {
Collection,
Entity,
ManyToOne,
MikroORM,
OneToMany,
PrimaryKey,
Property,
} from '@mikro-orm/sqlite';
class Part {
id!: string;
name!: string;
}
class Job {
id!: string;
jobConnections = new Collection<JobConnection>(this);
}
class JobConnection {
id!: string;
orderItems = new Collection<OrderItem>(this);
job?: Job;
}
class OrderItem {
id!: string;
part!: Part;
jobConnection?: JobConnection;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Part, OrderItem, JobConnection, Job],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(async () => {
await orm.close(true);
});
test(`nested eager not respected when populating non-eager parent`, async () => {
orm.em.create(Job, {
id: '1',
jobConnections: [
{
id: '1',
orderItems: [{ id: '1', part: { id: '1', name: 'part' } }],
},
],
});
orm.em.create(Job, {
id: '2',
jobConnections: [
{
id: '2',
orderItems: [{ id: '2', part: { id: '2', name: 'part' } }],
},
],
});
await orm.em.flush();
orm.em.clear();
const jobs = await orm.em.findAll(Job, {
populate: ['jobConnections.orderItems'],
});
expect(jobs[0].jobConnections[0].orderItems[0].part.name).toBeDefined();
});