Skip to content

Commit 57aed6e

Browse files
committed
feat: avoid populating hidden Collection fields
1 parent d3692a2 commit 57aed6e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class BooksService /* extends ... */ {
185185

186186
## Populating Relations
187187

188-
By default, `Collection` fields of the entity will be populated mandatorily. The user can populate relations by passing the `expand` query param like `book.owner.profile`, and you could specify which fields is allowed to be expanded by specifying the `expand.in` option when creating the query DTO.
188+
By default, the unhidden `Collection` fields of the entity will be populated mandatorily. The user can populate relations by passing the `expand` query param like `book.owner.profile`, and you could specify which fields is allowed to be expanded by specifying the `expand.in` option when creating the query DTO.
189189

190190
**You could populate any relations when handling the request and don't need to worry there will be extra relations expanded unexpectedly in the response. All the entities will be processed before responding to ensure only the relations mentioned in the `expand` query param are marked as _populated_ to shape the response, therefore, although `Collection` fields are populated mandatorily, they will be only an array of primary keys in the response if they are not mentioned in the `expand` query param.**
191191

src/services/mikro-crud-service.factory.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ export class MikroCrudServiceFactory<
6464

6565
this.collectionFields = this.entityMeta.relations
6666
.filter(
67-
({ reference }) =>
68-
reference == ReferenceType.ONE_TO_MANY ||
69-
reference == ReferenceType.MANY_TO_MANY
67+
({ reference, hidden }) =>
68+
!hidden &&
69+
(reference == ReferenceType.ONE_TO_MANY ||
70+
reference == ReferenceType.MANY_TO_MANY)
7071
)
7172
.map(({ name }) => name as NonFunctionPropertyNames<Entity>);
7273
}

0 commit comments

Comments
 (0)