EntitySchema helper you define the schema programmatically.
When creating new entity instances, you will need to use
em.create() method that will
create instance of internally created class.
Using this approach, metadata caching is automatically disabled as it is not needed.
It is very common to define a DTO (Data Transfer Object) to validate incoming request bodies and pass the request body data on to the other parts of your application. If you pass the DTO directly to the
create method it could lead to unexpected results. The data for the
create method should be provided as a POJO (Plain Old JS Object
You can achieve this by letting your DTO class extend the
PlainObject class. This way MikroORM knows it should be treated as such.
You can optionally use custom class for entity instances.
Then you can use the entity class as usual:
Do not forget that base entities needs to be discovered just like normal entities.
The parameter of
EntitySchema requires to provide either
extends will be automatically inferred. You can optionally pass
these additional parameters:
Every property then needs to contain a type specification - one of
Here are some examples of various property types:
As a value for
typeyou can also use one of