# ManyToManyAssociationField Fehler

**URL:** https://forum.shopware.com/t/manytomanyassociationfield-fehler/99440
**Category:** Programmierung
**Created:** [24. April 2023 um 13:59 UTC](https://forum.shopware.com/t/manytomanyassociationfield-fehler/99440 "2023-04-24T13:59:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)
#### Post date: [24. April 2023 um 13:59 UTC](https://forum.shopware.com/t/manytomanyassociationfield-fehler/99440/1 "2023-04-24T13:59:16Z")

</div>

Ich habe in meiner custom EntityDefinition ein `ManyToManyAssociationField`:

```php
(new ManyToManyAssociationField('assignedProducts', ProductDefinition::class, ProductBadgeAssignedProductsDefinition::class, 'product_badge_id', 'product_id')),

```

Viele Product-Badges können viele Products haben. Also habe ich noch eine Product Extension hinzugefügt:

```php
class ProductExtension extends EntityExtension
{
    public function extendFields(FieldCollection $collection): void
    {
        $collection->add(
            (new ManyToManyAssociationField(
                'productBadges',
                ProductBadgeDefinition::class,
                ProductBadgeAssignedProductsDefinition::class,
                'product_id',
                'product_badge_id'
            ))->addFlags(new Inherited())
        );
    }
    

    public function getDefinitionClass(): string
    {
        return ProductDefinition::class;
    }
}

```

Meinen Product Badges kann ich auch Produkten zuordnen. Möchte ich jetzt aber ein Produkt speichern, hat der Request `/api/_action/sync` einen Error:

```plaintext
An exception occurred while executing '
UPDATE `product` SET `productBadges` = IFNULL(
    (
        SELECT `kk_product_badge_assigned_products`.`product_id`
        FROM `kk_product_badge_assigned_products`
        WHERE `kk_product_badge_assigned_products`.`product_id` = `product`.id
        AND `kk_product_badge_assigned_products`.`product_version_id` = `product`.version_id
        LIMIT 1
    ),
    IFNULL(`product`.parent_id, `product`.id)
)
WHERE `product`.id IN (?, ?)
AND `product`.version_id = ?' with params ["\u00...fa", "\x0f...\x25"]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'productBadges' in 'field list'

```

Dadurch wird jetzt z.B. availableStock nicht aktualisiert…

Warum will der denn jetzt überhaupt das Feld `productBadges` aktualisieren? Das ist doch nur eine Association auf beiden Seiten…

---

<div class="post-metadata">

### Author: ![Anotherone](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Anotherone](https://forum.shopware.com/u/Anotherone)
#### Post date: [24. April 2023 um 17:43 UTC](https://forum.shopware.com/t/manytomanyassociationfield-fehler/99440/2 "2023-04-24T17:43:11Z")

</div>

Hab mich grad wegen einem ähnlichen Problem durch den Code gegraben, Auslöser ist der InheritanceUpdater (aufgerufen durch den ProductIndexer), der alle Vererbungen aktualisiert (dein ManyToMany ist „Inherited“). Offensichtlich fehlt das Feld productBadges in der Tabelle product. Wird normalerweise mit `$this->updateInheritance($connection, 'product', 'productBadges');` in der Migration erledigt.

---

<div class="post-metadata">

### Author: ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)
#### Post date: [25. April 2023 um 05:14 UTC](https://forum.shopware.com/t/manytomanyassociationfield-fehler/99440/3 "2023-04-25T05:14:18Z")

</div>

Ah stimmt, in der Reversed–Assosiation brauche ich das ja auch gar nicht. Habe es rausgenommen und jetzt funktioniert es. Vielen Dank!
