FusionWorks / react-admin-nestjsx-crud-dataprovider

Data provider which integrates React Admin with NestJS CRUD library
132 stars 26 forks source link

How to work with ReferenceArrayField / ReferenceArrayInput #13

Open henrik-d opened 4 years ago

henrik-d commented 4 years ago

Hi, first of all thanks for sharing the dataProvider. I have a problem with Many-to-Many relationsships.

A Book has many Authors. An Author writes many Books.

In React Admin in the books resource I want to display / edit the related authors using ReferenceArrayField / ReferenceArrayInput. The problem is that React Admin expects the following format:

// book  as required by React Admin
{
    "title": "Book Title",
    "auhors": [2,4,5] //just the authorIds
}

Whereas Nest-Crud generates and requires a list of objects with at least idto update the relationship.

// book  as required by Nest CRUD
{
    "title": "Book Title",
    "auhors": [{"id": 2}, {"id": 4}, {"id": 5}] //objects
}

What would you recommend? Can this issue be solved in the dataProvider or elsewhere in React Admin? Or is it best to solve it on the server side, e.g. with an interceptor?

Thanks!

pkramarczyk commented 4 years ago

Hey! I had the same issue. Just found this issue in ra repository and managed to make it work: https://github.com/marmelab/react-admin/issues/4125

Notice that it was fixed in the 3.0.4 version!