# Association-Vererbung funktioniert nicht

**URL:** <https://forum.shopware.com/t/association-vererbung-funktioniert-nicht/107301>\
**Category:** Shopware 6 (German)\
**Created:** [28. Mai 2025 um 12:32 UTC](https://forum.shopware.com/t/association-vererbung-funktioniert-nicht/107301 "2025-05-28T12:32:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![developer3](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@developer3](https://forum.shopware.com/u/developer3)\
**Post date:** [28. Mai 2025 um 12:32 UTC](https://forum.shopware.com/t/association-vererbung-funktioniert-nicht/107301/1 "2025-05-28T12:32:12Z")

</div>

Hallo zusammen,

ich versuche seit Tagen erfolglos die Vererbung einer Association hinzubekommen. Normale Inheritance-Felder funktionieren einwandfrei und übernehmen den Wert vom parent. Nur die Association bleibt in der DB immer null.

Ich habe mir die Docs ([Field Inheritance | Shopware Documentation](https://developer.shopware.com/docs/guides/plugins/plugins/framework/data-handling/field-inheritance.html#association-inheritance)) mehrfach durchgesehen, kann aber nicht erkennen, was ich falsch mache bzw. wo das Problem liegt:

Produkt-Extension-Definition  
(Vererbung von „product\_distributor\_id“ funktioniert, von „distributor“ nicht):

```auto
class ProductExtensionDefinition extends EntityDefinition
{
    public const ENTITY_NAME = 'product_extension';
    
    ...

    public function isInheritanceAware(): bool
    {
        return true;
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
            (new FkField('product_id', 'productId', ProductDefinition::class))->addFlags(new Required()),
            (new ReferenceVersionField(ProductDefinition::class, 'product_version_id'))->addFlags(new Required()),

            (new ParentFkField(self::class))->addFlags(new ApiAware()),
            (new ParentAssociationField(self::class, 'id'))->addFlags(new ApiAware()),
            (new ChildrenAssociationField(self::class))->addFlags(new ApiAware()),
            (new FkField('product_distributor_id', 'distributorId', ProductDistributorDefinition::class))->addFlags(new ApiAware(), new Inherited()),

            new OneToOneAssociationField('product', 'product_id', 'id', ProductDefinition::class, false),
            (new ManyToOneAssociationField('distributor', 'product_distributor_id', ProductDistributorDefinition::class, 'id'))->addFlags(new ApiAware(), new Inherited()),
        ]);
    }
}

```

Distributor-Definition:

```auto
class ProductDistributorDefinition extends EntityDefinition
{

    public const ENTITY_NAME = 'product_distributor';
    
    ...

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
            (new StringField('name', 'name'))->addFlags(new Required()),
            (new OneToManyAssociationField('productExtensions', ProductExtensionDefinition::class, 'product_distributor_id', 'id'))->addFlags(new RestrictDelete(), new ReverseInherited('distributor')),
        ]);
    }
}

```

Die dazugehörige Migration:

```auto
  $sql = <<<SQL
        CREATE TABLE IF NOT EXISTS product_extension (
                id BINARY(16) NOT NULL,
                product_id BINARY(16) NOT NULL,
                product_version_id BINARY(16) NOT NULL,
                parent_id BINARY(16) NULL,
                product_distributor_id BINARY(16) NULL,
                created_at DATETIME NOT NULL,
                updated_at DATETIME NULL,
                PRIMARY KEY (id),
                CONSTRAINT FK_product_extension_product FOREIGN KEY (product_id, product_version_id)
                    REFERENCES product (id, version_id) ON DELETE CASCADE ON UPDATE CASCADE,
                CONSTRAINT FK_product_extension_distributor_id FOREIGN KEY (product_distributor_id)
                    REFERENCES product_distributor (id) ON DELETE RESTRICT ON UPDATE CASCADE,
                CONSTRAINT FK_product_extension_parent_id FOREIGN KEY (parent_id)
                    REFERENCES product_extension (id) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

  CREATE TABLE IF NOT EXISTS product_distributor (
                id BINARY(16) NOT NULL,
                name VARCHAR(255) NOT NULL,
                created_at DATETIME NOT NULL,
                updated_at DATETIME NULL,
                PRIMARY KEY (id)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

SQL;

 $connection->executeStatement($sql);

 $this->updateInheritance($connection, 'product_extension', 'distributor');

```

UpdateInheritance legt zwar eine neue Spalte „distributor“ in der Tabelle „product\_extension“ an, allerdings bleiben die Werte in dieser Spalte immer null, egal, ob ich per Sync-API eine neue DistributorId setze, eine parentId übertrage etc.

Weiß jemand vielleicht, wo mein (Gedanken)-Fehler liegt?

Vielen Dank und viele Grüße  
Frank
