forked from mikro-orm/mikro-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): do not try to propagate changes to
mapToPk
relations
Closes mikro-orm#4254
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); | ||
}); |