ra-data-hasura-graphql
ra-data-hasura-graphql copied to clipboard
Support for editing many-to-many?
Hi there, thx for nice lib!
What is the current "out-of-the-box" support for editing many-to-many relationships?
More specifically, does the library currently support providing a SelectArrayInput or AutoCompleteArrayInput over a referenced table? (Without any custom parsing/mutation logic etc.)
So for example if my blog post has 2 topics assigned, it would default to show this:
But it would be possible to add additional topics from the blogpost table and save these relationships back to the blogpost_topic table.
//Pseudo code
<ReferenceManyField>
<ReferenceArrayInput>
<AutocompleteArrayInput />
</ReferenceArrayInput>
</ReferenceManyField>
If not, could you provide any hints on how our team of developers could help extend the functionality in this direction and we could submit a PR :) Thx!
@Steams - could you provide some feedback on this when you have a chance? This is functionality that we will also need.
@lapidus I'll start looking into this and get back to you
Thank you @Steams! Let me know if there's anything we could help out with from here.
Hey @lapidus, Did you find any way to edit many to many relationships. I am also stuck in this for the past few days. I was able to display the related data in list like this
<ReferenceManyField
label='Subjects'
reference='stream_subject'
target='stream_id'
>
<SingleFieldList>
<ReferenceField reference='subject' source='subject_id'>
<ChipField source='name' />
</ReferenceField>
</SingleFieldList>
</ReferenceManyField>
but for edit and update its not working. Do you have any idea how can we get this? Thank you!
I built my own CMS in the end ;) But this is a great initiative :)
I was able to make use of Hasura's nested mutation inserts and a few other nifty things to create a decent CRUD CMS in about 3 days.
But beware before going down that path, there's some pitfalls ...
@lapidus this might be late but I hope this would help others.
The way I approach this is modeling like NoSQL and query using _contains
. More details here.
subject {
id: uuid
name
topics: jsonb # array of topic ids
}
topic {
id
name
}
Below is a working example on a project I'm currently working. When #69 is merged, this should work out of the box.
<ReferenceArrayField
{...props}
reference="contacts"
source="contact_ids"
fullWidth
addLabel={false}
pagination={<Pagination />}
perPage={5}
>
<Datagrid>
<TextField label="Name" source="full_name" />
<TextField source="type" />
<TextField source="email" />
<TextField label="Phone" source="phone_number" />
<ContactListRowActions appraisal={props.record} />
</Datagrid>
</ReferenceArrayField>