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

Datastore cannot delete one to many relationship #5088

Closed
apoorvmote opened this issue Mar 13, 2020 · 8 comments · Fixed by #5778
Closed

Datastore cannot delete one to many relationship #5088

apoorvmote opened this issue Mar 13, 2020 · 8 comments · Fixed by #5778
Assignees
Labels
DataStore Related to DataStore category feature-request Request a new feature
Milestone

Comments

@apoorvmote
Copy link

Describe the bug
I have simple one to many relationship. I haven't even gotten to many part yet. I am just testing adding and deleting to one part of relationship. I can add but I cannot delete. I get this error
Failed to execute 'index' on 'IDBObjectStore': The specified index was not found

To Reproduce
npx create-react-app blog --use-npm --template typescript
amplify init
amplify add api not adding auth just trying to keep it simple.
add following schema

type Post @model {
  id: ID!
  title: String!
  postComments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}

type Comment @model
  @key(name: "byPost", fields: ["postID"]) {
  id: ID!
  postID: ID!
  content: String!
}

then I create post this part works.
But when I try to delete post then it errors out.
I haven't tried adding comments yet.

async function deletePost(id: string) {
    
    try {

      const original = await DataStore.query(Post, id)

      console.log(original)

      await DataStore.delete(original)

    } catch (err) {

      console.error(err)
    }
  }

I do get the original post but I just cannot delete it. I get following error

Failed to execute 'index' on 'IDBObjectStore': The specified index was not found

@apoorvmote apoorvmote added the to-be-reproduced Used in order for Amplify to reproduce said issue label Mar 13, 2020
@ashika01 ashika01 added the DataStore Related to DataStore category label Mar 13, 2020
@manueliglesias manueliglesias added feature-request Request a new feature and removed to-be-reproduced Used in order for Amplify to reproduce said issue labels Mar 27, 2020
@manueliglesias
Copy link
Contributor

Thank you @apoorvmote

We are tracking this together with the cli team.

There's work already started: aws-amplify/amplify-cli#3680

@manueliglesias manueliglesias added this to the DataStore milestone Mar 27, 2020
@hardchor
Copy link

hardchor commented Apr 7, 2020

The new warning looks good 👍 @manueliglesias!
Is there a ticket to track support for keyName?

@apoorvmote
Copy link
Author

This is upsetting now I get following error.
Error: DataStore does not support connection directive with keyName

Why did it not warn me before I did amplify push.
Breaking changes like this should have some kind of warning on blog post or on cli or change log or anywhere.

Is there a ticket to track support for keyName?

I am also interested in the same

@apoorvmote
Copy link
Author

There should also be warning on datastore. Because everything is saved in datastore locally but when you push to cloud then lots of things start to break. Many things don't sync with API for whatever reason.
So I always push to cloud before testing the app. I cannot just start testing/developing app with datastore alone.
There are lots of thing that can go wrong when amplify push. So I used to generate amplify codegen models after push is successful. But I have to change that now.

@undefobj
Copy link
Contributor

undefobj commented Apr 9, 2020

@apoorvmote by chance we actually looked at this earlier today, and there are two issues at play. First the keyName is indeed not supported yet for DataStore. We're looking at designing something simpler there but it is on our radar. The check put in place was to avoid problems but unfortunately it was added in a newer CLI version which I think you've upgraded to. I'd suggest reverting and updating your schema.

However there might be a bug here as well which is the crux of the issue that you've reported. We should be able to cascade the deletes in a 1:N relationship but the IDBObjectStore is unexpected. We'll look into this to see if we can reproduce. In the meantime I'll transfer this to the JavaScript repo as that issue is on the library side.

@undefobj
Copy link
Contributor

Following up for future reference: We updated the docs for Relational modeling. We made some improvements to the CLI, the library on how it handles this internally, and tried to be explicit about schemas in the documentation including how to use @key.

@myfairshare
Copy link

Hello, I have also run into this problem, is there a solution to this, thank you.

@github-actions
Copy link

github-actions bot commented May 9, 2022

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DataStore Related to DataStore category feature-request Request a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants