nazirov91 / ra-strapi-rest

React Admin data provider for Strapi.js
125 stars 40 forks source link

Add example for Relations to the Readme #31

Closed crimsdings closed 1 year ago

crimsdings commented 3 years ago

I fail to understand if this Data Provider is supposed to work with Strapi Realtions and React-Admins ReferenceManyField or ReferenceArrayField - can you please add examples to the ReadMe for those use cases ?

For my specific issue:

I have 2 collections Users and Groups - with a one user to many groups relation field in strapi (reference field is called re_groups in users and re_users in groups)

if i use a 1:1 relation this works without an issue

`

`

but if i use a ReferenceManyField target seems to be ignored or i simply dont understand what the target is supposed to be:

according to https://marmelab.com/react-admin/Fields.html#reference-fields

accepts a reference attribute, which specifies the resource to fetch for the related record. It also accepts a source attribute which defines the field containing the value to look for in the target field of the referenced resource. By default, this is the id of the resource (post.id in the previous example).

`

`

same goes for the ReferenceArrayField - basic examples with the relationship field of strapi should get added.

thank you!

crimsdings commented 3 years ago

@EdgarGomez https://github.com/nazirov91/ra-strapi-rest/issues/27 also seemed to have problems with the same issue - i dont know if he ever came up with a solution.

EdgarGomez commented 3 years ago

Hey @crimsdings can you try something like:

<ReferenceManyField label="Comments by" source="user" reference="users"> <SingleFieldList> <ChipField source="username" /> </SingleFieldList> </ReferenceManyField>
crimsdings commented 3 years ago

in the meantime i found out, that i dont need a reference field at all, since there is already the array in the json due to the strapi relation field so a:

`

            </ArrayField>`

did work for my use case - however now i dont know how to count the results in an arrayfield ;p

expanding the README for relations would be helpfull

nazirov91 commented 1 year ago

Hi!

Please see the readme file. I have updated the package to make it work with Strapi V4. Also added a demo repo for reference. Please open a new issue if the problem persists.

Thanks!