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
8
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
-
13
-
**Tip**: For a rendering a list of chips by default, use [the `<ReferenceArrayField>` component](./ReferenceArrayField.md) instead.
9
+
`<ReferenceArrayFieldBase>` fetches a list of referenced records (using the `dataProvider.getMany()` method), and puts them in a [`ListContext`](../list/useListContext.md). This component is headless, and its children need to use the data from this context to render the desired ui.
14
10
15
11
**Tip**: If the relationship is materialized by a foreign key on the referenced resource, use [the `<ReferenceManyFieldBase>` component](./ReferenceManyFieldBase.md) instead.
16
12
@@ -45,7 +41,7 @@ A typical `post` record therefore looks like this:
45
41
In that case, use `<ReferenceArrayFieldBase>` to display the post tag names as a list of chips, as follows:
`<ReferenceArrayFieldBase>` fetches the `tag` resources related to each `post` resource by matching `post.tag_ids` to `tag.id`.
83
79
84
-
You can change how the list of related records is rendered by passing a custom child reading the `ListContext` (e.g. a [`<DataTable>`](./DataTable.md)) or a render function prop. See the [`children`](#children) and the [`render`](#render) sections for details.
80
+
You can change how the list of related records is rendered by passing a custom child reading the `ListContext` (e.g. a `<DataTable>` component) or a render function prop. See the [`children`](#children) and the [`render`](#render) sections for details.
85
81
86
82
## Props
87
83
@@ -164,7 +160,6 @@ Alternatively to `children`, you can pass a `render` function prop to `<Referenc
164
160
165
161
For instance, to render only tags that are 'published', you can use the following code:
166
162
167
-
{% raw %}
168
163
```jsx
169
164
<ReferenceArrayFieldBase
170
165
label="Tags"
@@ -173,7 +168,6 @@ For instance, to render only tags that are 'published', you can use the followin
173
168
filter={{ is_published:true }}
174
169
/>
175
170
```
176
-
{% endraw %}
177
171
178
172
## `perPage`
179
173
@@ -187,15 +181,13 @@ For instance, to limit the display of related records to 10, you can use the fol
187
181
188
182
## `queryOptions`
189
183
190
-
Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` query](./useGetOne.md#aggregating-getone-calls) that fetches the referenced record.
184
+
Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` query](../data-fetching/useGetOne.md#aggregating-getone-calls) that fetches the referenced record.
191
185
192
-
For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
186
+
For instance, to pass [a custom `meta`](../data-fetching/Actions.md#meta-parameter):
`<ReferenceFieldBase>` is useful for displaying many-to-one and one-to-one relationships, e.g. the details of a user when rendering a post authored by that user.
10
-
`<ReferenceFieldBase>` 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 [`<ReferenceField>`](/ReferenceField.html)
6
+
`<ReferenceFieldBase>` 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 [`<ReferenceField>`](../components/ReferenceField.md)
11
7
12
8
## Usage
13
9
@@ -27,17 +23,18 @@ For instance, let's consider a model where a `post` has one author from the `use
27
23
In that case, use `<ReferenceFieldBase>` to display the post's author as follows:
`<ReferenceFieldBase>` fetches the data, puts it in a [`RecordContext`](./useRecordContext.md), and its up to its children to handle the rendering by accessing the `ReferencingContext` using the `useReferenceFieldContext` hook.
55
+
`<ReferenceFieldBase>` fetches the data, puts it in a [`RecordContext`](../common/useRecordContext.md), and its up to its children to handle the rendering by accessing the `ReferencingContext` using the `useReferenceFieldContext` hook.
59
56
60
57
It uses `dataProvider.getMany()` instead of `dataProvider.getOne()`[for performance reasons](#performance). When using several `<ReferenceFieldBase>` in the same page (e.g. in a `<DataTable>`), this allows to call the `dataProvider` once instead of once per row.
61
58
@@ -78,7 +75,7 @@ You can pass any component of your own as child, to render the related records a
78
75
You can access the list context using the `useReferenceFieldContext` hook.
@@ -146,9 +143,8 @@ You can customize this error message by passing a React element or a string to t
146
143
147
144
Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` query](./useGetOne.md#aggregating-getone-calls) that fetches the referenced record.
148
145
149
-
For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
146
+
For instance, to pass [a custom `meta`](../data/Actions.md#meta-parameter):
150
147
151
-
{% raw %}
152
148
```jsx
153
149
<ReferenceFieldBase
154
150
source="user_id"
@@ -159,7 +155,6 @@ For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
159
155
...
160
156
</ReferenceFieldBase>
161
157
```
162
-
{% endraw %}
163
158
164
159
## `reference`
165
160
@@ -215,14 +210,12 @@ By default, when used in a `<Datagrid>`, and when the user clicks on the column
**Note**: For prefetching to function correctly, your data provider must support [Prefetching Relationships](./DataProviders.md#prefetching-relationships). Refer to your data provider's documentation to verify if this feature is supported.
278
+
**Note**: For prefetching to function correctly, your data provider must support [Prefetching Relationships](../data/DataProviders.md#prefetching-relationships). Refer to your data provider's documentation to verify if this feature is supported.
288
279
289
280
**Note**: Prefetching is a frontend performance feature, designed to avoid flickers and repaints. It doesn't always prevent `<ReferenceFieldBase>` to fetch the data. For instance, when coming to a show view from a list view, the main record is already in the cache, so the page renders immediately, and both the page controller and the `<ReferenceFieldBase>` controller fetch the data in parallel. The prefetched data from the page controller arrives after the first render of the `<ReferenceFieldBase>`, so the data provider fetches the related data anyway. But from a user perspective, the page displays immediately, including the `<ReferenceFieldBase>`. If you want to avoid the `<ReferenceFieldBase>` to fetch the data, you can use the React Query Client's `staleTime` option.
290
281
291
282
## Access Control
292
283
293
-
If your authProvider implements [the `canAccess` method](./AuthProviderWriting.md#canaccess), React-Admin will verify whether users have access to the Show and Edit views.
284
+
If your authProvider implements [the `canAccess` method](../auth/AuthProviderWriting.md#canaccess), React-Admin will verify whether users have access to the Show and Edit views.
294
285
295
286
For instance, given the following `ReferenceFieldBase`:
0 commit comments