Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): log abstract entity names during discovery
Closes #4080
- Loading branch information
Showing
2 changed files
with
88 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,87 @@ | ||
import { EntitySchema, SimpleLogger } from '@mikro-orm/core'; | ||
import { MikroORM } from '@mikro-orm/sqlite'; | ||
|
||
abstract class BaseClass { | ||
|
||
id?: number; | ||
|
||
} | ||
|
||
interface BaseInterface { | ||
id?: number; | ||
} | ||
|
||
class DerivedClass extends BaseClass { | ||
|
||
name?: string; | ||
|
||
} | ||
|
||
class ImplementingClass implements BaseInterface { | ||
|
||
id?: number; | ||
name?: string; | ||
|
||
} | ||
|
||
const BaseClassSchema = new EntitySchema<BaseClass>({ | ||
name: 'BaseClass', | ||
abstract: true, | ||
properties: { | ||
id: { type: Number, primary: true }, | ||
}, | ||
}); | ||
|
||
const BaseInterfaceSchema = new EntitySchema<BaseInterface>({ | ||
name: 'BaseInterface', | ||
abstract: true, | ||
properties: { | ||
id: { type: Number, primary: true }, | ||
}, | ||
}); | ||
|
||
const DerivedClassSchema = new EntitySchema<DerivedClass>({ | ||
class: DerivedClass, | ||
extends: 'BaseClass', | ||
properties: { | ||
name: { type: String }, | ||
}, | ||
}); | ||
|
||
const ImplementingClassSchema = new EntitySchema<ImplementingClass>({ | ||
class: ImplementingClass, | ||
extends: 'BaseInterface', | ||
properties: { | ||
name: { type: String }, | ||
}, | ||
}); | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
const logger = jest.fn(); | ||
orm = await MikroORM.init({ | ||
entities: [ | ||
BaseClassSchema, | ||
DerivedClassSchema, | ||
BaseInterfaceSchema, | ||
ImplementingClassSchema, | ||
], | ||
dbName: `:memory:`, | ||
logger: msg => logger(msg), | ||
loggerFactory: options => new SimpleLogger(options), | ||
debug: true, | ||
}); | ||
expect(logger.mock.calls.toString()).not.toMatch('undefined'); | ||
await orm.schema.refreshDatabase(); | ||
}); | ||
|
||
afterAll(() => orm.close(true)); | ||
|
||
test('4080', async () => { | ||
orm.em.create(DerivedClassSchema, { name: 'foo' }); | ||
await orm.em.flush(); | ||
orm.em.clear(); | ||
|
||
await orm.em.findOneOrFail(DerivedClassSchema, { name: 'foo' }); | ||
}); |