You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
API Platform Admin handles `to-one` and `to-many` relations automatically.
4
4
5
-
Thanks to [the Schema.org support](schema.org.md), you can easily display the name of a related resource instead of its IRI.
5
+
Thanks to [the Schema.org support](./schema-org.md#displaying-related-resources-name-instead-of-its-iri), you can easily display the name of a related resource instead of its IRI.
6
6
7
7
## Embedded Relations
8
8
@@ -11,12 +11,10 @@ If a relation is an array of [embeddeds or an embedded](../core/serialization.md
11
11
The embedded data will be displayed as text field and editable as text input: the admin cannot determine the fields present in it.
12
12
To display the fields you want, see [this section](handling-relations.md#display-a-field-of-an-embedded-relation).
13
13
14
-
You can also ask the admin to automatically replace the embedded resources' data by their IRI,
15
-
by setting the `useEmbedded` parameter of the Hydra data provider to `false`.
16
-
Embedded data is inserted to a local cache: it will not be necessary to make more requests if you reference some fields of the embedded resource later on.
14
+
You can also ask the admin to return the embedded resources' IRI instead of the full record, by setting the `useEmbedded` parameter of the Hydra data provider to `false`.
**Tip:** Embedded data is inserted to a local cache: it will not be necessary to make more requests if you reference some fields of the embedded resource later on.
38
+
39
39
## Display a Field of an Embedded Relation
40
40
41
41
If you have an [embedded relation](../core/serialization.md#embedding-relations) and need to display a nested field, the code you need to write depends of the value of `useEmbedded` of the Hydra data provider.
42
42
43
-
If `true` (default behavior), you need to use the dot notation to display a field:
43
+
If `true` (default behavior), you can use the dot notation to display a field:
44
44
45
-
```javascript
45
+
```jsx
46
46
import {
47
47
HydraAdmin,
48
48
FieldGuesser,
@@ -51,16 +51,16 @@ import {
51
51
} from'@api-platform/admin';
52
52
import { TextField } from'react-admin';
53
53
54
-
constBooksList= (props) => (
55
-
<ListGuesser {...props}>
54
+
constBooksList= () => (
55
+
<ListGuesser>
56
56
<FieldGuesser source="title"/>
57
57
{/* Use react-admin components directly when you want complex fields. */}
58
58
<TextField label="Author first name" source="author.firstName"/>
@@ -96,9 +96,9 @@ For instance, if your API returns:
96
96
}
97
97
```
98
98
99
-
If you want to display the author first name in the list, you need to write the following code:
99
+
If you want to display the author first name in the list, you need to leverage React Admin's [`<ReferenceField>`](https://marmelab.com/react-admin/ReferenceField.html) to fetch the related record:
Let's go one step further thanks to the [customization capabilities](customizing.md) of API Platform Admin by adding autocompletion support to form inputs for relations.
134
+
Let's go one step further thanks to the customization capabilities of API Platform Admin by adding autocompletion support to form inputs for relations.
135
135
136
136
Let's consider an API exposing `Review` and `Book` resources linked by a `many-to-one` relation (through the `book` property).
137
137
@@ -192,9 +192,9 @@ class Book
192
192
193
193
Notice the "partial search" [filter](../core/filters.md) on the `title` property of the `Book` resource class.
194
194
195
-
Now, let's configure API Platform Admin to enable autocompletion for the relation selector:
195
+
Now, let's configure API Platform Admin to enable autocompletion for the book selector. We will leverage the [`<ReferenceInput>`](https://marmelab.com/react-admin/ReferenceInput.html) and [`<AutocompleteInput>`](https://marmelab.com/react-admin/AutocompleteInput.html) components from React Admin:
0 commit comments