# Produkt um vererbbares Boolean-Feld erweitern

**URL:** https://forum.shopware.com/t/produkt-um-vererbbares-boolean-feld-erweitern/89149
**Category:** Programmierung
**Created:** [14. Juli 2021 um 13:19 UTC](https://forum.shopware.com/t/produkt-um-vererbbares-boolean-feld-erweitern/89149 "2021-07-14T13:19:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![maximsteinhh](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@maximsteinhh](https://forum.shopware.com/u/maximsteinhh)
#### Post date: [14. Juli 2021 um 13:19 UTC](https://forum.shopware.com/t/produkt-um-vererbbares-boolean-feld-erweitern/89149/1 "2021-07-14T13:19:26Z")

</div>

Ich versuche gerade ein vererbbares Boolean-Feld für Produkte einzubauen aber irgendwie funktioniert das nicht. Wenn das Plugin aktiviert ist bekomme ich vom Backend immer den Fehler

> SQLSTATE[42S22]: Column not found: 1054 Unknown column ‚product.customizationExtension.parent\_id‘ in ‚field list‘

Das ist meine Entity:

```auto

class ProductCustomizationEntity extends Entity
{
    use EntityIdTrait;

    public const ENTITY_NAME = 'maxim_customization_extension';

    public function getEntityName(): string
    {
        return self::ENTITY_NAME;
    }

   public function getEntityClass(): string
    {
        return ExampleEntity::class;
    } 

    protected function defineFields(): FieldCollection
    { 
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
            new FkField('product_id', 'productId', ProductDefinition::class),
            (new BoolField('is_customizable', 'isCustomizable'))->addFlags(new Inherited()),
            new CreatedAtField(),
            new UpdatedAtField(),
            new OneToOneAssociationField('product', 'product_id', 'id', ProductDefinition::class, false),

            new ParentFkField(self::class),
            new ParentAssociationField(self::class, 'id'),
            new ChildrenAssociationField(self::class),
        ]);
    }
    

```

und eine Extension-Klasse:

```auto

class CustomizationExtension extends EntityExtension
{

    public const EXTENSION_NAME = 'customizationExtension';

    public function extendFields(FieldCollection $collection): void
    {
        
        $collection->add(
            (new OneToOneAssociationField(self::EXTENSION_NAME, 'id', 'product_id', CustomizationExtensionDefinition::class, true))
            ->addFlags(new Inherited())
        );
    }

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

```

und diese Migration:

```auto
class Migration1625938165Initial extends MigrationStep
{
    use InheritanceUpdaterTrait;

    public function getCreationTimestamp(): int
    {
        return 1625938165;
    }

    public function update(Connection $connection): void
    {

        // `is_customizable` BOOLEAN NULL,            
        $query = <<<SQL
        CREATE TABLE IF NOT EXISTS `maxim_customization_extension` (
            `id` INT NOT NULL,
            `product_id` INT NULL,
   
            `created_at` DATETIME(3) NOT NULL,
            `updated_at` DATETIME(3),
            PRIMARY KEY (id)
        )
            ENGINE = InnoDB
            DEFAULT CHARSET = utf8mb4
            COLLATE = utf8mb4_unicode_ci;
        SQL;

        $connection->executeStatement($query);
        $this->updateInheritance($connection, 'maxim_customization_extension', 'is_customizable');
    }

```

Das boolean Feld wird im Query jetzt nicht eingetragen weil ich in der updateInheritance Anweisung immer den Fehler erhalten habe, dass die Spalte schon existiert.

---

<div class="post-metadata">

### Author: ![sawden](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@sawden](https://forum.shopware.com/u/sawden)
#### Post date: [10. August 2021 um 03:28 UTC](https://forum.shopware.com/t/produkt-um-vererbbares-boolean-feld-erweitern/89149/2 "2021-08-10T03:28:19Z")

</div>

Hallo,

ich versuche aktuell auch das Produkt mit einem OneToOneAssociationField zu erweitern und bekomme dabei den selben Fehler ausgegeben.

Habe bereits alles probiert aber keine Lösung finden können… Glaube fast schon, dass es sich hier um einen Bug im Shopware Core handelt. 🤔

Wie hast du das Problem gelöst?

---

<div class="post-metadata">

### Author: ![sawden](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@sawden](https://forum.shopware.com/u/sawden)
#### Post date: [11. August 2021 um 03:37 UTC](https://forum.shopware.com/t/produkt-um-vererbbares-boolean-feld-erweitern/89149/3 "2021-08-11T03:37:14Z")

</div>

Ich habe den Fehler an Shopware gemeldet und hoffe, dass die Plugins mit der nächsten Version wieder funktionieren. 😕

> <https://github.com/shopware/platform/issues/2015>
>
> \### PHP Version
> 
> 7.4.22
> 
> \### Shopware Version
> 
> 6.4.3.0
> 
> \### Expected behaviour
> 
> …It should be possible to expand the product with a "OneToOneAssociationField" as described in the \[documentation\](https://developer.shopware.com/docs/guides/plugins/plugins/framework/data-handling/add-complex-data-to-existing-entities#adding-a-field-with-database).
> 
> \*\*\_This error is very critical because none of the plugins that extend the product entity can currently be used.\_\*\* 
> 
> 
> \### Actual behaviour
> 
> Currently, all plugins that extend the product entity with a "OneToOneAssociationField" lead to a 500 error when saving or editing products in the administration.
> 
> An error message appears in the upper corner.
> !\[sw6\_err\](https://user-images.githubusercontent.com/36924392/128963822-7151448e-4aaf-42b9-a64e-181f81e1cb1d.png)
> 
> In the developer tools you can see that there is an Internal Server Error.
> !\[sw6\_err2\](https://user-images.githubusercontent.com/36924392/128963981-3ab40ec4-4a76-47b3-9659-96e994636166.png)
> \`SQLSTATE\[42S22\]: Column not found: 1054 Unknown column 'OTO' in 'field list'\`
> 
> \### How to reproduce
> 
> Create a Plugin that extends the "Product" with a "OneToOneAssociationField" or download/clone my example plugin that reproduce this error.
> 
> \[Github repository here\](https://github.com/sawden/OneToOneProductExtensionTest)
> 
> \- Install the plugin.
> \- Open the administration and edit an existing product (add a space in to the name) or try to create a new product.
> \- Press "Save"
> 
> ...\*\*Internal Server Error\*\*...
