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

Foreign Key Constraint error when deleting an element that is referenced in other elements as code scope #61

Closed
DeividasDavidav opened this issue Jun 9, 2023 · 3 comments

Comments

@DeividasDavidav
Copy link
Contributor

DeividasDavidav commented Jun 9, 2023

Describe the bug
When using onDeleteElement() function from IModelImporter to delete an element, if an element is referenced by other elements in their code scopes, it throws Foreign key constraint error. That is because ElementTreeDeleter doesn't find elements with code scope references to specific element when deleting it. (Already created an issue with possible solution in itwins-core (iTwin/itwinjs-core#5576) but they said that ElementTreeDeleter shouldn't solve this relationship issue)

To Reproduce

  1. Create the first element
  2. Create the second element that references the first element in its code scope
  3. Try to delete the first element (can use onDeleteElement() from IModelImporter)
  4. See "error deleting element" error (errorNumber: 65553)

Expected behavior
When deleting an element, it should also process the elements that reference the element in their code scopes.

Desktop (please complete the applicable information):

  • iTwin.js Version 3.6.1
  • Node Version 18.16.0
@MichaelBelousov
Copy link
Contributor

We can port your suggested fix to a ElementCascadingDeleter in the transformer. Given you already have sample fix code in your original core issue, would you be willing to make a PR?

Do we need to add additional sanity checks though that the transformer should only delete this element if its other references (the scope one that currently errors) are also being deleted?

@DeividasDavidav
Copy link
Contributor Author

Okay, I will make a PR and add a sanity check that ensures that this element would only be deleted if all code scope references are also being deleted.

DeividasDavidav added a commit that referenced this issue Jun 26, 2023
…hich is referenced in code scopes (#75)

Added ElementCascadingDeleter, which works similarly to
ElementTreeDeleter, but also finds elements that reference this element
in their code scopes and deletes those elements.

#61
@MichaelBelousov
Copy link
Contributor

this was fixed by #75, closing

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

No branches or pull requests

2 participants