【问题标题】:Shopware 6 custom plugin, deleting extension on delete parent does not workShopware 6 custom plugin, deleting extension on delete parent does not work
【发布时间】:2022-12-27 21:32:09
【问题描述】:

I have an extension created following the manual Adding complex data to existing entities.
My product has with this extension another property like e.g product_color. On delete the product the prop (entity table) product_color still remains in the database.

// Migration%123%ProductColor.php

...
    public function update(Connection $connection): void
    {
        $sql = <<<SQL
CREATE TABLE `product_color` (
  `id` binary(16) NOT NULL,
  `product_id` binary(16) DEFAULT NULL,
  `color` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` datetime(3) NOT NULL,
  `updated_at` datetime(3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL;
        $connection->executeStatement($sql);
    }
...

Questions:

  • how to make the additional property deletable on delete its parent (delete cascade)?
  • where are the corresponding manual how to achieve this?

【问题讨论】:

    标签: plugins shopware6


    【解决方案1】:

    There is a flag CascadeDelete which you can add to your association field:

    ->addFlags(new CascadeDelete())
    

    This should lead to an ON CASCADE DELETE entry in the SQL, if you create it with dal:create:schema.

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 2022-12-01
      • 2022-12-02
      • 2022-12-27
      • 2020-10-18
      • 1970-01-01
      • 2022-12-01
      • 2019-03-11
      • 1970-01-01
      相关资源
      最近更新 更多