I am trying to understand what the right approach would be to address nested endpoints, let's assume I have a many to many books
and authors
relationship, and an API which exposes api/authors
, api/books
, and api/authors/{id}/books
. This is a common design pattern.
The CRUD on api/authors
works beautifully in react-admin. However, under the authors <Show>
I want to show a <Datagrid>
of all the books with pagination and sorting, which my api makes available under api/authors/{id}/books
.
What is the right approach to make a datagrid of such a nested endpoint?
I've looked into the <ReferenceManyField>
which works well in the one to many context but doesn't allow accessing nested endpoints, only filtering an endpoint.
Ideally I would want something that is along the lines of:
<Show {...props}>
<TabbedShowLayout>
<Tab label="Books">
<NestedResourceField reference="books" nestedResource={`authors/${props.record.id}/books`} pagination={<Pagination/>} >
<Datagrid>
<TextField source="name" />
</Datagrid>
</NestedResourceField>
</Tab>
</TabbedShowLayout>
</Show>
Note that <NestedResourceField>
is a hypothetical component which would have a behavior very similar to <ReferenceManyField>
but would accept a nested endpoint under nestedResource
instead of target
.
I am struggling to understand what the design strategy should be for the hypothetical <NestedResourceField>
in order to re-use as much of the react-admin framework as possible.
It would be straightforward to "manually" do the fetch myself and list the content but then I would lose all the pagination, filtering, sorting, etc... that comes with react-admin and the fact that books
is an already defined resource.
My question is similar to these unanswered questions:
custom path for resource route in react-admin
Edit
Turns out an almost identical question which I had not found previously was posted here: Support for resource nesting
api/authors/{id}/books
? Thanks – Spectator