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

Update handling-relations.md with an example of ReferenceArrayInput #1144

Open
wants to merge 1 commit into
base: 2.5
Choose a base branch
from

Conversation

loeyan
Copy link

@loeyan loeyan commented Jul 24, 2020

It took me plenty of hours to get nested objects with referenceArrayInput running. By a lucky hit i found the fix for it! (https://html.developreference.com/article/11019200/How+to+reuse+subresource+data+for+referenced+inputs+in+React-admin%3F)

Also i struggeled with the referenceInput. Please at those special cases for nested. Feel free to edit :-)

It took me plenty of hours to get nested objects with referenceArrayInput running. By a lucky hit i found the fix for it! (https://html.developreference.com/article/11019200/How+to+reuse+subresource+data+for+referenced+inputs+in+React-admin%3F) 

Also i struggeled with the referenceInput. Please at those special cases for nested.
@@ -326,6 +326,15 @@ const ReviewsEdit = props => (
>
<AutocompleteInput optionText="title" />
</ReferenceInput>
// or
<ReferenceInput
source="book.@id"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using the format prop is clearer than having this source.

...

<ReferenceArrayInput source="books" reference="books_reference" label="Books" sort={{field: 'title', order: 'ASC'}}
format={v => (v ? v.map(i => (i["@id"] 11? i["@id"] : i)) : [])}>
Copy link
Member

@alanpoulain alanpoulain Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
format={v => (v ? v.map(i => (i["@id"] 11? i["@id"] : i)) : [])}>
format={v => (v ? v.map(i => (i["@id"] || i)) : [])}>

<EditGuesser {...props}>
...

<ReferenceArrayInput source="books" reference="books_reference" label="Books" sort={{field: 'title', order: 'ASC'}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you indent properly?


Let's say `useEmbedded` parameter is set to `true` and you have nested a nested objects array you want to use in an ReferenceArrayInput. ReferenceArrayInput expects an array of ids. In this case you have to tell it, where it finds those ids. This is done via "format"

```javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to add this example above than to write again the example.

@@ -345,3 +354,42 @@ export default () => (
```

The autocomplete field should now work properly!

Let's say `useEmbedded` parameter is set to `true` and you have nested a nested objects array you want to use in an ReferenceArrayInput. ReferenceArrayInput expects an array of ids. In this case you have to tell it, where it finds those ids. This is done via "format"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Let's say `useEmbedded` parameter is set to `true` and you have nested a nested objects array you want to use in an ReferenceArrayInput. ReferenceArrayInput expects an array of ids. In this case you have to tell it, where it finds those ids. This is done via "format"
Let's say `useEmbedded` parameter is set to `true` and you have nested an array of objects you want to use in a `ReferenceArrayInput`. `ReferenceArrayInput` expects an array of ids. In this case, you have to tell it where to find those ids. This is done by using the `format` prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants