Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Better document ReferenceManyField's source prop #8726

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion docs/ReferenceManyField.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const PostList = () => (
| `target` | Required | `string` | - | Target field carrying the relationship on the referenced resource, e.g. 'user_id' |
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'books' |
| `children` | Required | `Element` | - | One or several elements that render a list of records based on a `ListContext` |
| `source` | Optional | `string` | `id` | Name of the property to display |
| `source` | Optional | `string` | `id` | Target field carrying the relationship on the source record (usually 'id') |
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records, passed to `getManyReference()` |
| `pagination` | Optional | `Element` | - | Pagination element to display pagination controls. empty by default (no pagination) |
| `perPage` | Optional | `number` | 25 | Maximum number of referenced records to fetch |
Expand Down Expand Up @@ -217,6 +217,20 @@ By default, it orders the possible values by id desc. You can change this order
```
{% endraw %}

## `source`

By default, `ReferenceManyField` uses the `id` field as target for the reference. If the foreign key points to another field of your record, you can select it with the `source` prop.

```jsx
<ReferenceManyField
target="post_id"
reference="comments"
source="_id"
>
...
</ReferenceManyField>
```

## `target`

Name of the field carrying the relationship on the referenced resource. For instance, if an `author` has many `books`, and each book resource exposes an `author_id` field, the `target` would be `author_id`.
Expand Down