ra-data-hasura-graphql icon indicating copy to clipboard operation
ra-data-hasura-graphql copied to clipboard

Support for editing many-to-many?

Open lapidus opened this issue 4 years ago • 6 comments

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: image

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!

lapidus avatar Apr 18 '20 12:04 lapidus

@Steams - could you provide some feedback on this when you have a chance? This is functionality that we will also need.

cpursley avatar Apr 18 '20 15:04 cpursley

@lapidus I'll start looking into this and get back to you

Steams avatar Apr 20 '20 21:04 Steams

Thank you @Steams! Let me know if there's anything we could help out with from here.

lapidus avatar Apr 21 '20 06:04 lapidus

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!

akamit21 avatar May 29 '20 08:05 akamit21

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 avatar May 29 '20 08:05 lapidus

@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>

jasper95 avatar Nov 29 '20 01:11 jasper95