mayteio / ra-aws-amplify

🎩 Create backends for your aws-amplify project at the speed of light with react-admin
MIT License
42 stars 7 forks source link

Example of many to many relationship #8

Open mayteio opened 4 years ago

mayteio commented 4 years ago

In the example, a post can have many editors.

type Post
  @model
  {
  id: ID!
  title: String!
  content: String
  editors: [PostEditor] @connection(name: "PostEditors")
}

type PostEditor
  @model {
  id: ID!
  post: Post! @connection(name: "PostEditors")
  editor: User! @connection(name: "UserEditors")
}

type User
  @model {
  id: ID!
  username: String!
  posts: [PostEditor] @connection(name: "UserEditors")
}
mayteio commented 4 years ago

Create works nicely on the feature/many-to-many branch though I have yet to get update or delete working.

Basically, via redux-sagas, we listen for CRUD_CREATE_SUCCESS, CRUD_UPDATE_SUCCESS, CRUD_DELETE_SUCCESS and fire off new dataProvider calls depending on what we're trying to do. See here.

Delete would be easy - in the example app, there is a PostCategory connection (many to many) with a queryField postCategorysByPost. You'd simple query this with the postId, then use dataProvider.delete to delete each connection.

Update is a little trickier: