Skip to content

Commit

Permalink
fix(core): do not try to propagate changes to mapToPk relations
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan authored and jsprw committed May 7, 2023
1 parent a36e154 commit 96defd3
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/features/unit-of-work/GH4254.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Cascade, Entity, LoadStrategy, OneToOne, PrimaryKey, Property } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/sqlite';

@Entity()
export class OrderSummary {

@OneToOne({
entity: () => Order,
onDelete: 'cascade',
primary: true,
mapToPk: true,
})
orderId!: number;

@Property()
prop!: string;

}

@Entity()
export class Order {

@PrimaryKey()
id!: number;

@OneToOne(() => OrderSummary, 'orderId', {
cascade: [Cascade.ALL],
eager: true,
})
summary!: OrderSummary;

}

let orm: MikroORM;

beforeAll(async () => {
orm = await MikroORM.init({
dbName: ':memory:',
entities: [Order, OrderSummary],
});
await orm.schema.createSchema();
});

afterAll(async () => {
await orm.close(true);
});

test(`GH issue 1352`, async () => {
const entity = orm.em.create(Order, {
id: 4,
summary: orm.em.create(OrderSummary, {
orderId: 4,
prop: '123',
}),
});
orm.em.persist(entity);
await orm.em.flush();
});

test(`GH issue 4254`, async () => {
orm.em.create(Order, {
id: 4,
summary: {
orderId: 4,
prop: '123',
},
});
});

0 comments on commit 96defd3

Please sign in to comment.