iTwin / imodel-transformer

API for exporting an iModel's parts and also importing them into another iModel
MIT License
3 stars 2 forks source link

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

Closed DeividasDavidav closed 1 year ago

DeividasDavidav commented 1 year ago

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 (https://github.com/iTwin/itwinjs-core/issues/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):

MichaelBelousov commented 1 year ago

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 commented 1 year ago

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.

MichaelBelousov commented 1 year ago

this was fixed by #75, closing