Skip to content

Commit

Permalink
Merge pull request #8726 from marmelab/ReferenceManyField-doc-source-…
Browse files Browse the repository at this point in the history
…prop

[Doc] Better document `ReferenceManyField`'s `source` prop
  • Loading branch information
djhi authored Mar 13, 2023
2 parents 5e5ec09 + 52d5859 commit 50f6924
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 50f6924

Please sign in to comment.