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 propagation during hydration dont produce extra upd…
…ates Closes #3941
- Loading branch information
Showing
5 changed files
with
115 additions
and
7 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
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,85 @@ | ||
import { Collection, Entity, helper, ManyToOne, OneToMany, OneToOne, PrimaryKey, Property, Ref } from '@mikro-orm/core'; | ||
import { MikroORM } from '@mikro-orm/sqlite'; | ||
|
||
@Entity() | ||
class Organization { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@OneToOne({ | ||
entity: () => License, | ||
ref: true, | ||
}) | ||
license!: Ref<License>; | ||
|
||
@OneToMany(() => Workspace, workspace => workspace.organization) | ||
workspaces = new Collection<Workspace>(this); | ||
|
||
@Property() | ||
name!: string; | ||
|
||
} | ||
|
||
@Entity() | ||
class License { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@OneToOne(() => Organization, organization => organization.license) | ||
organization!: Ref<Organization>; | ||
|
||
@Property() | ||
name!: string; | ||
|
||
} | ||
|
||
@Entity() | ||
class Workspace { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@Property() | ||
name!: string; | ||
|
||
@ManyToOne(() => Organization, { ref: true }) | ||
organization!: Ref<Organization>; | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [Organization, License, Workspace], | ||
dbName: ':memory:', | ||
}); | ||
await orm.schema.refreshDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await orm.close(); | ||
}); | ||
|
||
test('3941', async () => { | ||
const organization = orm.em.create(Organization, { | ||
name: 'Organization', | ||
license: { | ||
name: 'License', | ||
}, | ||
workspaces: [ | ||
{ name: 'Workspace' }, | ||
], | ||
}); | ||
await orm.em.flush(); | ||
orm.em.clear(); | ||
|
||
const workspace = await orm.em.findOneOrFail(Workspace, organization.workspaces[0].id); | ||
const license = await orm.em.findOneOrFail(License, { organization: { workspaces: workspace } }); | ||
|
||
orm.em.getUnitOfWork().computeChangeSets(); | ||
expect(orm.em.getUnitOfWork().getChangeSets()).toHaveLength(0); | ||
expect(helper(license.organization).__originalEntityData).toEqual({ id: 1, license: 1 }); | ||
}); |