diff --git a/guides/plugins/plugins/framework/data-handling/add-complex-data-to-existing-entities.md b/guides/plugins/plugins/framework/data-handling/add-complex-data-to-existing-entities.md index d7e1ff09d7..6b7930f751 100644 --- a/guides/plugins/plugins/framework/data-handling/add-complex-data-to-existing-entities.md +++ b/guides/plugins/plugins/framework/data-handling/add-complex-data-to-existing-entities.md @@ -88,6 +88,7 @@ Let's start with the `CustomExtension` class by adding a new field in the `exten namespace Swag\BasicExample\Extension\Content\Product; use Shopware\Core\Content\Product\ProductDefinition; use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete; use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; @@ -96,7 +97,7 @@ class CustomExtension extends EntityExtension public function extendFields(FieldCollection $collection): void { $collection->add( - new OneToOneAssociationField('exampleExtension', 'id', 'product_id', ExampleExtensionDefinition::class, true) + (new OneToOneAssociationField('exampleExtension', 'id', 'product_id', ExampleExtensionDefinition::class, true))->addFlags(new CascadeDelete()) ); } @@ -115,6 +116,9 @@ As you can see, we're adding a new `OneToOneAssociationField`. Its parameters ar * `referenceClass`: The class name of the definition that we want to connect via the association. * `autoload`: As the name suggests, this parameter defines if this association should always be loaded by default when the product is loaded. In this case, we definitely want that. +Associations marked with the `CascadeDelete` flag are considered in the clone process. Take a look at the [clone behaviour](../../../../../resources/references/adr/2020-07-02-control-clone-behavior.md) +If the associated entity should not be cloned when cloning a product having it, change it to `CascadeDelete(false)` or remove the flag. + #### Creating ExampleExtensionDefinition You most likely noticed the new class `ExampleExtensionDefinition`, which we're going to create now. It will contain the actual string field that we wanted to add to the product.