Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): ensure M:N collections are not dirty after populating of i…
…nverse side Closes #3287
- Loading branch information
Showing
4 changed files
with
63 additions
and
8 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
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
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
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,56 @@ | ||
import { Collection, Entity, ManyToMany, MikroORM, PrimaryKey } from '@mikro-orm/core'; | ||
|
||
@Entity() | ||
export class Group { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@ManyToMany({ | ||
entity: 'Participant', | ||
mappedBy: 'groups', | ||
}) | ||
participants = new Collection<Participant>(this); | ||
|
||
} | ||
|
||
@Entity() | ||
export class Participant { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@ManyToMany({ | ||
entity: () => Group, | ||
inversedBy: 'participants', | ||
}) | ||
groups = new Collection<Group>(this); | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [Participant], | ||
dbName: ':memory:', | ||
type: 'better-sqlite', | ||
}); | ||
await orm.getSchemaGenerator().createSchema(); | ||
}); | ||
|
||
afterAll(() => orm.close(true)); | ||
|
||
test('removing items from m:n (GH 3287)', async () => { | ||
const group1 = new Group(); | ||
group1.participants.add(new Participant()); | ||
await orm.em.fork().persistAndFlush(group1); | ||
|
||
const group = await orm.em.findOneOrFail(Group, group1, { | ||
populate: ['participants'], | ||
}); | ||
|
||
orm.em.remove(group); | ||
|
||
await orm.em.flush(); | ||
}); |