-
-
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): fix auto-refresh detection in
em.find
for inlined embedd…
…ed properties Closes #4904
- Loading branch information
Showing
6 changed files
with
146 additions
and
56 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,108 @@ | ||
import { MikroORM } from '@mikro-orm/sqlite'; | ||
import { EntitySchema, ReferenceType } from '@mikro-orm/core'; | ||
import { mockLogger } from '../../helpers'; | ||
|
||
class TestEntity1 { | ||
|
||
id: string; | ||
customProp: CustomProp; | ||
|
||
constructor(id: string, customProp: CustomProp) { | ||
this.id = id; | ||
this.customProp = customProp; | ||
} | ||
|
||
} | ||
|
||
class TestEntity2 { | ||
|
||
id: string; | ||
customProp: CustomProp; | ||
|
||
constructor(id: string, customProp: CustomProp) { | ||
this.id = id; | ||
this.customProp = customProp; | ||
} | ||
|
||
} | ||
|
||
class CustomProp { | ||
|
||
someValue: string; | ||
|
||
constructor(someValue: string) { | ||
this.someValue = someValue; | ||
} | ||
|
||
} | ||
|
||
const TestEntity1Schema = new EntitySchema({ | ||
class: TestEntity1, | ||
properties: { | ||
id: { | ||
type: 'text', | ||
primary: true, | ||
}, | ||
customProp: { | ||
type: 'CustomProp', | ||
reference: ReferenceType.EMBEDDED, | ||
object: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const TestEntity2Schema = new EntitySchema({ | ||
class: TestEntity2, | ||
properties: { | ||
id: { | ||
type: 'text', | ||
primary: true, | ||
}, | ||
customProp: { | ||
type: 'CustomProp', | ||
reference: ReferenceType.EMBEDDED, | ||
object: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const CustomPropSchema = new EntitySchema({ | ||
class: CustomProp, | ||
embeddable: true, | ||
properties: { | ||
someValue: { | ||
type: 'text', | ||
}, | ||
}, | ||
}); | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [TestEntity1Schema, TestEntity2Schema, CustomPropSchema], | ||
dbName: `:memory:`, | ||
}); | ||
|
||
await orm.schema.createSchema(); | ||
}); | ||
|
||
afterAll(() => orm.close(true)); | ||
|
||
test('preserve data fields that match pivot field', async () => { | ||
const e1 = new TestEntity1('abc', new CustomProp('yyy')); | ||
await orm.em.insert(TestEntity1, e1); | ||
|
||
const e2 = new TestEntity2('def', new CustomProp('xxx')); | ||
await orm.em.insert(TestEntity2, e2); | ||
|
||
const mock = mockLogger(orm); | ||
|
||
await orm.em.findOne(TestEntity1, 'abc'); | ||
await orm.em.findOne(TestEntity1, 'abc'); // should not trigger SQL query | ||
|
||
await orm.em.findOne(TestEntity2, 'def'); | ||
await orm.em.findOne(TestEntity2, 'def'); // should not trigger SQL query | ||
|
||
expect(mock).toBeCalledTimes(2); | ||
}); |
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