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
Use `<ReferenceArrayFieldBase>` to display a list of related records, via a one-to-many relationship materialized by an array of foreign keys.
10
10
11
11
`<ReferenceArrayFieldBase>` fetches a list of referenced records (using the `dataProvider.getMany()` method), and puts them in a [`ListContext`](./useListContext.md). This component is headless, and its children need to use the data from this context to render the desired ui.
12
-
For a component handling the UI too use [the `<ReferenceArrayField>` component](./ReferenceArrayField.md) instead.
12
+
13
+
**Tip**: For a rendering a list of chips by default, use [the `<ReferenceArrayField>` component](./ReferenceArrayField.md) instead.
13
14
14
15
**Tip**: If the relationship is materialized by a foreign key on the referenced resource, use [the `<ReferenceManyFieldBase>` component](./ReferenceManyFieldBase.md) instead.
15
16
@@ -100,11 +101,9 @@ You can change how the list of related records is rendered by passing a custom c
100
101
101
102
## `children`
102
103
103
-
You can pass any component of your own as child, to render the list of related records as you wish.
104
-
You can access the list context using the `useListContext` hook.
104
+
You can pass any React component as child, to render the list of related records based on the `ListContext`.
Alternatively to children you can pass a `render` function prop to `<ReferenceArrayFieldBase>`. The `render` prop will receive the `ListContext` as its argument, allowing to inline the `render` logic.
135
-
When receiving a `render` prop the `<ReferenceArrayFieldBase>` component will ignore the children property.
133
+
Alternatively to `children`, you can pass a `render` function prop to `<ReferenceArrayFieldBase>`. The `render` prop will receive the `ListContext` as its argument, allowing to inline the rendering logic.
136
134
137
135
```jsx
138
136
<ReferenceArrayFieldBase
@@ -157,6 +155,8 @@ When receiving a `render` prop the `<ReferenceArrayFieldBase>` component will ig
157
155
/>
158
156
```
159
157
158
+
**Tip**: When receiving a `render` prop, the `<ReferenceArrayFieldBase>` component will ignore the `children` property.
159
+
160
160
## `filter`
161
161
162
162
`<ReferenceArrayFieldBase>` fetches all the related records, and displays them all, too. You can use the `filter` prop to filter the list of related records to display (this works by filtering the records client-side, after the fetch).
`<ReferenceManyFieldBase>` is useful for displaying a list of related records via a one-to-many relationship, when the foreign key is carried by the referenced resource.
10
10
11
-
This component fetches a list of referenced records by a reverse lookup of the current `record.id` in the `target` field of another resource (using the `dataProvider.getManyReference()` REST method), and puts them in a [`ListContext`](./useListContext.md). This component is headless, and its children need to use the data from this context to render the desired ui.
12
-
For a component handling the UI too use [the `<ReferenceManyField>` component](./ReferenceManyField.md) instead.
11
+
This component fetches a list of referenced records by a reverse lookup of the current `record.id` in the `target` field of another resource (using the `dataProvider.getManyReference()` REST method), and puts them in a [`ListContext`](./useListContext.md).
12
+
13
+
This component is headless. It relies on its `children` or a `render` prop to render the desired ui.
13
14
14
15
**Tip**: If the relationship is materialized by an array of ids in the initial record, use [the `<ReferenceArrayFieldBase>` component](./ReferenceArrayFieldBase.md) instead.
15
16
16
17
## Usage
17
18
18
-
### With children
19
-
20
19
For instance, if an `author` has many `books`, and each book resource exposes an `author_id` field:
21
20
22
21
```
@@ -35,6 +34,14 @@ For instance, if an `author` has many `books`, and each book resource exposes an
`<ReferenceManyFieldBase>` accepts a `reference` attribute, which specifies the resource to fetch for the related record. It also accepts a `source` attribute which defines the field containing the value to look for in the `target` field of the referenced resource. By default, this is the `id` of the resource (`authors.id` in the previous example).
Copy file name to clipboardExpand all lines: docs/ReferenceOneFieldBase.md
+28-18Lines changed: 28 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,16 +21,17 @@ This field fetches a one-to-one relationship, e.g. the details of a book, when u
21
21
22
22
`<ReferenceOneFieldBase>` behaves like `<ReferenceManyFieldBase>`: it uses the current `record` (a book in this example) to build a filter for the book details with the foreign key (`book_id`). Then, it uses `dataProvider.getManyReference('book_details', { target: 'book_id', id: book.id })` to fetch the related details, and takes the first one.
23
23
24
-
`<ReferenceOneFieldBase>` is a headless component, handling only the logic. This allows to use any UI library for the render. For a version based on MUI see [`<ReferenceOneField>`](/ReferenceOneField.html)
24
+
`<ReferenceOneFieldBase>` is a headless component, handling only the logic and relying on its `children` or `render` prop to render the UI.
25
25
26
-
For the inverse relationships (the book linked to a book_detail), you can use a [`<ReferenceFieldBase>`](./ReferenceFieldBase.md).
26
+
**Tip**: For a version based on MUI, see [`<ReferenceOneField>`](/ReferenceOneField.html)
27
+
28
+
**Tip**: For the inverse relationships (the book linked to a book_detail), you can use a [`<ReferenceFieldBase>`](./ReferenceFieldBase.md).
27
29
28
30
## Usage
29
31
30
32
Here is how to render a field of the `book_details` resource inside a Show view for the `books` resource:
@@ -196,7 +206,7 @@ For instance, if a product has prices in many currencies, and you only want to r
196
206
197
207
## `link`
198
208
199
-
By default, `<ReferenceOneFieldBase>`will set pass a links to the edition page of the related record in the context.link. You can disable this behavior by setting the `link` prop to `false`.
209
+
By default, `<ReferenceOneFieldBase>`populates the context with a `link` value that links to the edition page of the related record. You can disable this behavior by setting the `link` prop to `false`.
0 commit comments