Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): do not map array types as
Loaded
when partially loaded
Closes #5123
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
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,38 @@ | ||
import { Entity, PrimaryKey, Property, JsonType } from '@mikro-orm/core'; | ||
import { MikroORM } from '@mikro-orm/sqlite'; | ||
|
||
@Entity() | ||
class A { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@Property({ type: JsonType }) | ||
array!: B[]; | ||
|
||
} | ||
|
||
interface B { | ||
test: string; | ||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [A], | ||
dbName: ':memory:', | ||
}); | ||
await orm.schema.createSchema(); | ||
}); | ||
|
||
test('GH #5123', async () => { | ||
const a = orm.em.create(A, { array: [{ test: 'test' }] }); | ||
await orm.em.persistAndFlush(a); | ||
|
||
const a1 = await orm.em.fork().findOneOrFail(A, 1); | ||
const a2 = await orm.em.fork().findOneOrFail(A, 1, { fields: ['array'] }); | ||
|
||
expect(a1.array.filter(i => i)).toEqual([{ test: 'test' }]); | ||
expect(a2.array.filter(i => i)).toEqual([{ test: 'test' }]); | ||
}); |