🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Deleting a translation document with self-reference error

16 replies
Last updated: Sep 22, 2022
Issue deleting a translation document that has reference to itself in another language. I tried to delete via Sanity Cli
sanity documents delete
but same error. Any advice?
Details
the mutation(s) failed: Document "ElLnRMEzVGBvCslc1mXoT__i18n_es" cannot be deleted as there are references to it from "ElLnRMEzVGBvCslc1mXoT"
Sep 22, 2022, 6:28 PM
Hey
user P
! You need to remove that reference from the document before deleting.
Sep 22, 2022, 6:29 PM
How do I remove the reference of the page itself?
Sep 22, 2022, 6:30 PM
The document I want to delete is a Spanish version of the English page
Sep 22, 2022, 6:31 PM
There is no option to remove the reference (?)
Sep 22, 2022, 6:31 PM
The document I want to delete is a Spanish version of the same page in English
Sep 22, 2022, 6:32 PM
You can query for any documents that reference that id (using
references(_id)
), then unset that reference either manually or through the API . This reference behavior is described in that plugin's read me here .
Sep 22, 2022, 6:39 PM
Thanks will read it up
Sep 22, 2022, 6:41 PM
I should note that the readme I linked is more about how to control this behavior in the future, but not so helpful in your current situation 😅
Sep 22, 2022, 6:51 PM
Based on the readme, I do have
referenceBehavior
set to strong. Updating it to weak doesn’t help in this case since the reference was set earlier when the translated document was created.
Sep 22, 2022, 6:55 PM
If I understood correctly based on https://www.sanity.io/docs/js-client#removing-unsetting-fields
I should unset (remove) the reference field to
ElLnRMEzVGBvCslc1mXoT
from the Spanish document id
ElLnRMEzVGBvCslc1mXoT__i18n_es
Sep 22, 2022, 6:56 PM
Yes, I believe that's correct.
Sep 22, 2022, 6:59 PM
From the Spanish document
ElLnRMEzVGBvCslc1mXoT__i18n_es
I can see
__i18n_base
(containing reference to
ElLnRMEzVGBvCslc1mXoT
is the field I shall remove using the API .What are you referring to when you said manually?
Sep 22, 2022, 7:05 PM
Manually means you've set an actual schema inside of your studio's UI to remove it. It doesn't seem like that's the case here.
Sep 22, 2022, 7:06 PM
Confirming deleting the reference field via API enable manual delete of the document later 🙂
Sep 22, 2022, 7:22 PM
Thanks for the tip!
Sep 22, 2022, 7:22 PM
Awesome! Glad it worked out!
Sep 22, 2022, 7:44 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?