Skip to content

Commit

Permalink
fix(core): log abstract entity names during discovery
Browse files Browse the repository at this point in the history
Closes #4080
  • Loading branch information
B4nan committed Feb 28, 2023
1 parent ff1dfb6 commit e721ad7
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/metadata/EntitySchema.ts
Expand Up @@ -224,7 +224,7 @@ export class EntitySchema<T = any, U = never> {
}

get name(): EntityName<T> {
return this._meta.name!;
return this._meta.className;
}

/**
Expand Down
87 changes: 87 additions & 0 deletions tests/issues/GH4080.test.ts
@@ -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' });
});

0 comments on commit e721ad7

Please sign in to comment.