Skip to content

Commit

Permalink
Merge pull request #2243 from marcpicaud/patch-3
Browse files Browse the repository at this point in the history
docs(mikroorm): add a caveat about serialization
  • Loading branch information
kamilmysliwiec committed Mar 14, 2022
2 parents 7954b80 + 89c7247 commit 4e53ef1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions content/recipes/mikroorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ object.
> still need CLI config with the full list of entities. On the other hand, we can
> use globs there, as the CLI won't go thru webpack.

#### Serialization

> warning **Note** MikroORM wraps every single entity relation in a `Reference<T>` or a `Collection<T>` object, in order to provide better type-safety. This will make [Nest's built-in serializer](/techniques/serialization) blind to any wrapped relations. In other words, if you return MikroORM entities from your HTTP or WebSocket handlers, all of their relations will NOT be serialized.
Luckily, MikroORM provides a [serialization API](https://mikro-orm.io/docs/serializing) which can be used in lieu of `ClassSerializerInterceptor`.

```typescript
@Entity()
export class Book {
@Property({ hidden: true }) // Equivalent of class-transformer's `@Exclude`
hiddenField = Date.now();

@Property({ persist: false }) // Similar to class-transformer's `@Expose()`. Will only exist in memory, and will be serialized.
count?: number;

@ManyToOne({ serializer: value => value.name, serializedName: 'authorName' }) // Equivalent of class-transformer's `@Transform()`
author: Author;
}
```

#### Request scoped handlers in queues

> info **info** `@UseRequestContext()` decorator was added in v4.1.0
Expand Down

0 comments on commit 4e53ef1

Please sign in to comment.