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

Example of many to many relationship #8

Open
mayteio opened this issue Mar 18, 2020 · 1 comment
Open

Example of many to many relationship #8

mayteio opened this issue Mar 18, 2020 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@mayteio
Copy link
Owner

mayteio commented Mar 18, 2020

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 mayteio added the documentation Improvements or additions to documentation label Mar 18, 2020
@mayteio
Copy link
Owner Author

mayteio commented Apr 3, 2020

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:

  • get all connections via postCategorysByPost queryField
  • separate them into two lists:
    • those that exist in the form values that don't in the DynamoDB record (create them)
    • those that don't exist in the form values but do in the DynamoDB record (delete them)

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

No branches or pull requests

1 participant