Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fix extra updates caused by bigint type
Mapped types have a `ensureComparable` option that allows them to ensure the mapped value will be comparable, this is used to normalize things like JSON or bigint shapes. While the mechanism itself was working, we were calling `registerManaged` twice, and only the first call did hydration and therefore had correct values. In some cases, the second call did override the original entity data back to the numeric value (which might be returned from mysql/sqlite). This removes the second call, as it was clearly not necessary, this is already handled from inside the `factory.create()` with `merge: true`. Closes #4249
- Loading branch information
Showing
2 changed files
with
59 additions
and
5 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,59 @@ | ||
import { BigIntType, Entity, ManyToOne, PrimaryKey, wrap } from '@mikro-orm/core'; | ||
import { MikroORM } from '@mikro-orm/mysql'; | ||
import { mockLogger } from '../../helpers'; | ||
|
||
@Entity() | ||
class Author { | ||
|
||
@PrimaryKey({ type: BigIntType }) | ||
id!: string; | ||
|
||
} | ||
|
||
@Entity() | ||
class Post { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@ManyToOne({ entity: () => Author }) | ||
author: Author; | ||
|
||
constructor(author: Author) { | ||
this.author = author; | ||
} | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
let postId: number; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
dbName: 'mikro_orm_4249', | ||
port: 3308, | ||
entities: [Author, Post], | ||
}); | ||
await orm.schema.refreshDatabase(); | ||
|
||
const em = orm.em.fork(); | ||
const author = new Author(); | ||
const post = new Post(author); | ||
em.persist(post); | ||
await em.flush(); | ||
postId = post.id; | ||
}); | ||
|
||
afterAll(async () => { | ||
await orm.close(true); | ||
}); | ||
|
||
test('4249', async () => { | ||
const em = orm.em.fork(); | ||
const post = await em.findOneOrFail(Post, postId); | ||
await wrap(post.author).init(); | ||
|
||
const mock = mockLogger(orm); | ||
await em.flush(); | ||
expect(mock.mock.calls).toEqual([]); | ||
}); |