Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many to many relationships #408

Closed
andreo opened this issue Mar 9, 2017 · 5 comments
Closed

Many to many relationships #408

andreo opened this issue Mar 9, 2017 · 5 comments

Comments

@andreo
Copy link

andreo commented Mar 9, 2017

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

@fzaninotto
Copy link
Member

Since admin-on-rest provides no special system for it, 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!

@leesei
Copy link
Contributor

leesei commented Mar 13, 2017

I'm looking into how to use the crudGetMany action. I think a good reference is https://github.com/marmelab/admin-on-rest-demo/blob/master/src/commands/Basket.js

Example:
https://marmelab.com/admin-on-rest-demo/#/commands/550?_k=80befq
This implements the basket on the right hand side where products are fetched with crudGetMany action.

@leesei
Copy link
Contributor

leesei commented Mar 14, 2017

Related: #429

@andreo
Copy link
Author

andreo commented Mar 15, 2017

How could an editable oneToMany list be implemented?

There are two actions:

  1. Add related item
  2. Delete related item

As I understand - a state of the items (new, deleted, unchanged) should be stored in the redux state (oneToMany). Then after "Save" button, the changes "new" and "deleted" are sent to the backend?

We can represetn the relation (A <-> B) as a separate resource (A_B): { a_id: 1, b_id: 3}
Or as an attribute-array.

@fzaninotto
Copy link
Member

ReferenceArrayField and ReferenceArrayInput is as far as we'll get for now. I consider it solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants