Set proper cascade behaviour on one-to-many product references

This commit is contained in:
infernosquad 2015-11-10 18:38:35 +05:00
parent 091525df5a
commit 8ab3060239
2 changed files with 47 additions and 3 deletions

View file

@ -0,0 +1,44 @@
<?php
namespace Sylius\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20151110183626 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_product DROP FOREIGN KEY FK_677B9B749E2D1A41');
$this->addSql('ALTER TABLE sylius_product DROP FOREIGN KEY FK_677B9B749DF894ED');
$this->addSql('ALTER TABLE sylius_product DROP FOREIGN KEY FK_677B9B74E64AACD3');
$this->addSql('ALTER TABLE sylius_product ADD CONSTRAINT FK_677B9B749E2D1A41 FOREIGN KEY (shipping_category_id) REFERENCES sylius_shipping_category (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE sylius_product ADD CONSTRAINT FK_677B9B749DF894ED FOREIGN KEY (tax_category_id) REFERENCES sylius_tax_category (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE sylius_product ADD CONSTRAINT FK_677B9B74E64AACD3 FOREIGN KEY (restricted_zone) REFERENCES sylius_zone (id) ON DELETE SET NULL');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_product DROP FOREIGN KEY FK_677B9B749DF894ED');
$this->addSql('ALTER TABLE sylius_product DROP FOREIGN KEY FK_677B9B749E2D1A41');
$this->addSql('ALTER TABLE sylius_product DROP FOREIGN KEY FK_677B9B74E64AACD3');
$this->addSql('ALTER TABLE sylius_product ADD CONSTRAINT FK_677B9B749DF894ED FOREIGN KEY (tax_category_id) REFERENCES sylius_tax_category (id)');
$this->addSql('ALTER TABLE sylius_product ADD CONSTRAINT FK_677B9B749E2D1A41 FOREIGN KEY (shipping_category_id) REFERENCES sylius_shipping_category (id)');
$this->addSql('ALTER TABLE sylius_product ADD CONSTRAINT FK_677B9B74E64AACD3 FOREIGN KEY (restricted_zone) REFERENCES sylius_zone (id)');
}
}

View file

@ -22,17 +22,17 @@
<field name="variantSelectionMethod" column="variant_selection_method" type="string" nullable="false" />
<many-to-one field="taxCategory" target-entity="Sylius\Component\Taxation\Model\TaxCategoryInterface">
<join-column name="tax_category_id" referenced-column-name="id" nullable="true" />
<join-column name="tax_category_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
<gedmo:versioned />
</many-to-one>
<many-to-one field="shippingCategory" target-entity="Sylius\Component\Shipping\Model\ShippingCategoryInterface">
<join-column name="shipping_category_id" referenced-column-name="id" nullable="true" />
<join-column name="shipping_category_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
<gedmo:versioned />
</many-to-one>
<many-to-one field="restrictedZone" target-entity="Sylius\Component\Addressing\Model\ZoneInterface">
<join-column name="restricted_zone" referenced-column-name="id" nullable="true" />
<join-column name="restricted_zone" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
</many-to-one>
<many-to-many field="taxons" inversed-by="products" target-entity="Sylius\Component\Taxonomy\Model\TaxonInterface">