quaerateum
Version:
Simple typescript ORM for node.js based on data-mapper, unit-of-work and identity-map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JS.
43 lines (29 loc) • 934 B
Markdown
---
---
# Using entity constructors
Internally, `MikroORM` never calls entity constructor, so you are free to use it as you wish.
The constructor will be called only when you instantiate the class yourself via `new` operator,
so it is a handy place to require your data when creating new entity.
For example following `Book` entity definition will always require to set `title` and `author`,
but `publisher` will be optional:
```typescript
export class Book {
_id: ObjectID;
title: string;
author: Author;
publisher: Publisher;
tags = new Collection<BookTag>(this);
constructor(title: string, author: Author) {
this.title = title;
this.author = author;
}
}
export interface Book extends IEntity { }
```
[← Back to table of contents](index.md#table-of-contents)