Skip to content

Commit b256ae4

Browse files
davidpodholadunglas
authored andcommitted
Update handling-relations-to-collections.md (#319)
1 parent a4d92fe commit b256ae4

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

admin/handling-relations-to-collections.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ import parseHydraDocumentation from 'api-doc-parser/lib/hydra/parseHydraDocument
8282

8383
const entrypoint = 'https://demo.api-platform.com';
8484

85-
class Admin extends Component {
86-
state = {api: null};
85+
export default class extends Component {
86+
state = {api: null, resources: null};
8787

8888
componentDidMount() {
89-
parseHydraDocumentation(entrypoint).then(api => {
90-
const r = api.resources;
91-
89+
parseHydraDocumentation(entrypoint).then({api, resources} => {
9290
const books = r.find(r => 'books' === r.name);
9391

9492
// Set the field in the list and the show views
@@ -107,19 +105,17 @@ class Admin extends Component {
107105
</ReferenceArrayInput>
108106
;
109107

110-
this.setState({api: api});
108+
this.setState({api, resources});
111109
}
112110
)
113111
}
114112

115113
render() {
116114
if (null === this.state.api) return <div>Loading...</div>;
117115

118-
return <AdminBuilder api={this.state.api} restClient={hydraClient(entrypoint)}/>
116+
return <AdminBuilder api={this.state.api} restClient={hydraClient({entrypoint: entrypoint, resources: this.state.resources})}/>
119117
}
120118
}
121-
122-
export default Admin;
123119
```
124120

125121
The admin now properly handles this `to-many` relation!
@@ -131,7 +127,7 @@ We'll make one last improvement to our admin: transforming the relation selector
131127
Start by adding a "partial search" filter on the `name` property of the `Book` resource class.
132128

133129
```yaml
134-
# etc/packages/api_platform.yaml
130+
# config/api_filters.yml
135131

136132
services:
137133
person.search_filter:

0 commit comments

Comments
 (0)