Skip to content

Commit

Permalink
Merge pull request #11 from jacquesbh/fix/undefined-shipment
Browse files Browse the repository at this point in the history
Fix undefined shipment.order
  • Loading branch information
lanfisis authored Sep 16, 2021
2 parents 8dc55e2 + 5356484 commit a6dba80
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/Migrations/Version20210915210206.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of Monsieur Biz' Shipping Slot plugin for Sylius.
*
* (c) Monsieur Biz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusShippingSlotPlugin\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20210915210206 extends AbstractMigration
{
public function getDescription(): string
{
return 'Cascade shipment deletion to slot deletion. Also remove slots without shipment.';
}

public function up(Schema $schema): void
{
$this->addSql('DELETE FROM monsieurbiz_shipping_slot_slot WHERE shipment_id IS NULL');
$this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot DROP FOREIGN KEY FK_3BD6F1F67BE036FC');
$this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot ADD CONSTRAINT FK_3BD6F1F67BE036FC FOREIGN KEY (shipment_id) REFERENCES sylius_shipment (id) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot DROP FOREIGN KEY FK_3BD6F1F67BE036FC');
$this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot ADD CONSTRAINT FK_3BD6F1F67BE036FC FOREIGN KEY (shipment_id) REFERENCES sylius_shipment (id) ON DELETE SET NULL');
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/doctrine/Slot.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<gedmo:timestampable on="update"/>
</field>
<one-to-one field="shipment" target-entity="Sylius\Component\Shipping\Model\ShipmentInterface" inversed-by="slot">
<join-column name="shipment_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
<join-column name="shipment_id" referenced-column-name="id" nullable="true" on-delete="CASCADE" />
</one-to-one>
</entity>
</doctrine-mapping>
3 changes: 3 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
"doctrine/dbal": {
"version": "2.12.0"
},
"doctrine/deprecations": {
"version": "v0.5.3"
},
"doctrine/doctrine-bundle": {
"version": "1.12",
"recipe": {
Expand Down

0 comments on commit a6dba80

Please sign in to comment.