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 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. *