Skip to content

Commit ca58f66

Browse files
fix: Re-show hidden PHP code snippet and add clarifying sentence (#1403)
1 parent f70397d commit ca58f66

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

core/serialization.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ In the following JSON document, the relation from a book to an author is by defa
252252

253253
It is possible to embed related objects (in their entirety, or only some of their properties) directly in the parent
254254
response through the use of serialization groups. By using the following serialization groups annotations (`@Groups`),
255-
a JSON representation of the author is embedded in the book response:
255+
a JSON representation of the author is embedded in the book response. As soon as any of the author's attributes is in
256+
the `book` group, the author will be embedded.
256257

257258
[codeSelector]
258259

@@ -282,6 +283,26 @@ class Book
282283
}
283284
```
284285

286+
```yaml
287+
# api/config/api_platform/resources/Book.yaml
288+
App\Entity\Book:
289+
attributes:
290+
normalization_context:
291+
groups: ['book']
292+
293+
# api/config/serializer/Book.yaml
294+
App\Entity\Book:
295+
attributes:
296+
name:
297+
groups: ['book']
298+
author:
299+
groups: ['book']
300+
```
301+
302+
[/codeSelector]
303+
304+
[codeSelector]
305+
285306
```php
286307
<?php
287308
// api/src/Entity/Person.php
@@ -305,20 +326,6 @@ class Person
305326
```
306327

307328
```yaml
308-
# api/config/api_platform/resources/Book.yaml
309-
App\Entity\Book:
310-
attributes:
311-
normalization_context:
312-
groups: ['book']
313-
314-
# api/config/serializer/Book.yaml
315-
App\Entity\Book:
316-
attributes:
317-
name:
318-
groups: ['book']
319-
author:
320-
groups: ['book']
321-
322329
# api/config/serializer/Person.yaml
323330
App\Entity\Person:
324331
attributes:

0 commit comments

Comments
 (0)