-
-
Notifications
You must be signed in to change notification settings - Fork 495
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 issue extra updates when there are no matching chan…
…gesets Closes #5510
- Loading branch information
Showing
2 changed files
with
75 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
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,63 @@ | ||
import { MikroORM, Entity, OneToOne, PrimaryKey, Property } from '@mikro-orm/postgresql'; | ||
import { mockLogger } from '../helpers'; | ||
|
||
@Entity() | ||
class Other { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@Property() | ||
name!: string; | ||
|
||
@Property({ nullable: true, onUpdate: () => new Date() }) | ||
updatedAt?: Date; | ||
|
||
} | ||
|
||
@Entity() | ||
class Test { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@Property() | ||
name!: string; | ||
|
||
@Property({ nullable: true, onUpdate: () => new Date() }) | ||
updatedAt?: Date; | ||
|
||
@OneToOne(() => Other, { nullable: true }) | ||
other?: Other; | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
dbName: '5510', | ||
entities: [Test], | ||
}); | ||
await orm.schema.refreshDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await orm.close(true); | ||
}); | ||
|
||
it('should merge all changes of one record into one sql update statement', async () => { | ||
const tid = await orm.em.insert(Test, { name: 'Foo' }); | ||
const test = await orm.em.findOne(Test, { id: tid }); | ||
|
||
const other = new Other(); | ||
other.name = 'Foo'; | ||
test!.other = other; | ||
|
||
const mock = mockLogger(orm); | ||
await orm.em.flush(); | ||
|
||
expect(mock.mock.calls).toHaveLength( | ||
[['begin'], ['insert into other'], ['update test'], ['commit']].length, | ||
); | ||
}); |