From c2ff8bb6547ae7d27826e415d637df8a8fb4a294 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Mon, 12 Feb 2024 13:43:20 +0000 Subject: [PATCH 1/2] delete relations if the element was deleted for a site --- src/fields/BaseRelationField.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/fields/BaseRelationField.php b/src/fields/BaseRelationField.php index ac0092780b8..221e6f17006 100644 --- a/src/fields/BaseRelationField.php +++ b/src/fields/BaseRelationField.php @@ -1013,6 +1013,22 @@ public function afterElementSave(ElementInterface $element, bool $isNew): void parent::afterElementSave($element, $isNew); } + /** + * @inheritdoc + */ + public function afterElementDeleteForSite(ElementInterface $element): void + { + if ($this->localizeRelations) { + Db::delete(DbTable::RELATIONS, [ + 'fieldId' => $this->id, + 'sourceSiteId' => $element->siteId, + 'sourceId' => $element->id, + ]); + } + + parent::afterElementDeleteForSite($element); + } + /** * Normalizes the available sources into select input options. * From 1ea6c83e3de24f35f9442d4077e90deaee2ded85 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 13 Feb 2024 15:17:37 -0800 Subject: [PATCH 2/2] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6792c47df5..2d52c8be0b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed a bug where GraphQL schema edit pages could include empty category headings. - Fixed a bug where asset slideouts weren’t showing validation errors on the Filename field. ([#14329](https://github.com/craftcms/cms/issues/14329)) - Fixed a bug where element slideouts would open when long-pressing on an element’s “Remove” button within an element select input. +- Fixed a bug where relations weren’t getting deleted when an element was deleted for a site. ([#14347](https://github.com/craftcms/cms/issues/14347)) ## 4.7.2.1 - 2024-02-08