Skip to content

Using discriminatorValue causes ignored child entities #923

@alisd23

Description

@alisd23

Describe the bug
When using the discriminatorValue setup for STI entities as described here, I am seeing some strange behaviour when combining with an abstract base (root) class.

The reproduction has 1 base class (Person) and 3 child entities (Chef, Gardener, Teacher).

When I log the metadata I see 2 issues (1 definite, 1 potential):

  1. The discriminator map is wrong. The abstract root class, Person, is present when it shouldn't be and the Gardener entity is missing.
discriminatorMap: { chef: 'Chef', person: 'Person', teacher: 'Teacher' }
  1. The abstract root class, Person, is marked as abstract: false in the metadata. I'm not familiar with the internals so this might not be a bug, but it seems wrong given the Person class is abstract and I do not want it included in the generated discriminator map.

This is causing entities to not be entered correctly for the missing child entities.

To Reproduce
Steps to reproduce the behavior:

  1. Go here to the reproduction
  2. Run yarn start:dev - watch the output of metadata found from the entity classes

Expected behavior
Only the non-abstract child entities, Chef, Teacher, and Gardener should exist in the discriminator map, and Person should be excluded.

Versions

Dependency Version
node 12.18.3
typescript 4.0.3
mikro-orm 4.1.1
your-driver MySQL

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions