Defining Entities
Entities are simple javascript objects (so called POJO) without restrictions and without the need to extend base classes. Using entity constructors works as well - they are never executed for managed entities (loaded from database). Every entity is required to have a primary key.
Modeling Entity Relationships
There are 4 types of entity relationships in MikroORM:
Entity Manager
Persist and Flush
Updating Entity Values
Updating Entity Values with assign()
Unit of Work
MikroORM uses the Identity Map pattern to track objects. Whenever you fetch an object from the database, MikroORM will keep a reference to this object inside its UnitOfWork.
Identity Map
MikroORM uses identity map in background, so we will always get the same instance of one entity.
Collections
OneToMany and ManyToMany properties are stored in a Collection wrapper.
Query Conditions
When you want to make complex queries, we can easily end up with a lot of boilerplate code full of curly brackets:
Populating relations
MikroORM is capable of loading large nested structures while maintaining good performance, querying each database table only once. Imagine you have this nested structure:
Type-Safe Relations
Entity relations are mapped to entity references - instances of the entity that have at least the primary key available. This reference is stored in identity map, so you will get the same object reference when fetching the same document from database.
Transactions and Concurrency
Starting v3.4, transactions are also supported in MongoDB driver.
Entity Repository
Entity Repositories are thin layers on top of EntityManager. They act as an extension point, so you can add custom methods, or even alter the existing ones. The default EntityRepository implementation just forwards the calls to underlying EntityManager instance.
Inheritance Mapping
Mapped Superclasses
Cascading
From v4.2, cascade merging is no longer configurable (and is kept enabled for all relations).
Query Builder
Since v4, we need to make sure we are working with correctly typed EntityManager or EntityRepository to have access to createQueryBuilder() method.
Using raw SQL query fragments
raw() helper