0

What is a proper way to define many to many relationships?

I have the relation:

Master <-many-to-many-> Service

REST API:

/services?filter={"master_id": 123}

This code shows all related services:

<ReferenceManyField label="Services" reference="services" target="master_id">
<Datagrid>
<TextField source="name" />
<EditButton />
</Datagrid>
</ReferenceManyField>

How can I implement Add/Delete actions inside ReferenceManyField?

Andreo
  • 597
  • 5
  • 19

1 Answers1

1

As answered in a similar question in the admin-on-rest issue tracker (please avoid duplicate questions, it gives more work to the maintainers), admin-on-rest provides no special system for it, so you'll have to do it in React. This means querying the first table, then, upon reception of the response, query the second table.

You could easily do it in a componentWillMount(). If you're more adventurous, you could also do it with the Redux state. If you happen to go that far, please open a PR to let us benefit from your solution!

Scott
  • 17,127
  • 5
  • 53
  • 64
François Zaninotto
  • 7,068
  • 2
  • 35
  • 56