From b4f3e3b60a0b5c6737cc4f7733853496d2c2dca2 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 1 Jul 2014 02:36:46 +0200 Subject: [PATCH] Fixed wrong fk in product table --- core/lib/Thelia/Model/Map/BrandTableMap.php | 3 +- core/lib/Thelia/Model/Map/ProductTableMap.php | 2 +- local/config/schema.xml | 2 +- setup/thelia.sql | 2 +- setup/update/2.0.3.sql | 84 +++++++++++++++---- 5 files changed, 72 insertions(+), 21 deletions(-) diff --git a/core/lib/Thelia/Model/Map/BrandTableMap.php b/core/lib/Thelia/Model/Map/BrandTableMap.php index 55e41bfa5..e7bced253 100644 --- a/core/lib/Thelia/Model/Map/BrandTableMap.php +++ b/core/lib/Thelia/Model/Map/BrandTableMap.php @@ -174,7 +174,7 @@ class BrandTableMap extends TableMap public function buildRelations() { $this->addRelation('BrandImageRelatedByLogoImageId', '\\Thelia\\Model\\BrandImage', RelationMap::MANY_TO_ONE, array('logo_image_id' => 'id', ), 'SET NULL', 'RESTRICT'); - $this->addRelation('Product', '\\Thelia\\Model\\Product', RelationMap::ONE_TO_MANY, array('id' => 'brand_id', ), 'RESTRICT', 'RESTRICT', 'Products'); + $this->addRelation('Product', '\\Thelia\\Model\\Product', RelationMap::ONE_TO_MANY, array('id' => 'brand_id', ), 'SET NULL', 'RESTRICT', 'Products'); $this->addRelation('BrandDocument', '\\Thelia\\Model\\BrandDocument', RelationMap::ONE_TO_MANY, array('id' => 'brand_id', ), 'CASCADE', 'RESTRICT', 'BrandDocuments'); $this->addRelation('BrandImageRelatedByBrandId', '\\Thelia\\Model\\BrandImage', RelationMap::ONE_TO_MANY, array('id' => 'brand_id', ), 'CASCADE', 'RESTRICT', 'BrandImagesRelatedByBrandId'); $this->addRelation('BrandI18n', '\\Thelia\\Model\\BrandI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'BrandI18ns'); @@ -200,6 +200,7 @@ class BrandTableMap extends TableMap { // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + ProductTableMap::clearInstancePool(); BrandDocumentTableMap::clearInstancePool(); BrandImageTableMap::clearInstancePool(); BrandI18nTableMap::clearInstancePool(); diff --git a/core/lib/Thelia/Model/Map/ProductTableMap.php b/core/lib/Thelia/Model/Map/ProductTableMap.php index 64d176029..4633d8a23 100644 --- a/core/lib/Thelia/Model/Map/ProductTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductTableMap.php @@ -211,7 +211,7 @@ class ProductTableMap extends TableMap { $this->addRelation('TaxRule', '\\Thelia\\Model\\TaxRule', RelationMap::MANY_TO_ONE, array('tax_rule_id' => 'id', ), 'RESTRICT', 'RESTRICT'); $this->addRelation('Template', '\\Thelia\\Model\\Template', RelationMap::MANY_TO_ONE, array('template_id' => 'id', ), 'SET NULL', null); - $this->addRelation('Brand', '\\Thelia\\Model\\Brand', RelationMap::MANY_TO_ONE, array('brand_id' => 'id', ), 'RESTRICT', 'RESTRICT'); + $this->addRelation('Brand', '\\Thelia\\Model\\Brand', RelationMap::MANY_TO_ONE, array('brand_id' => 'id', ), 'SET NULL', 'RESTRICT'); $this->addRelation('ProductCategory', '\\Thelia\\Model\\ProductCategory', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'ProductCategories'); $this->addRelation('FeatureProduct', '\\Thelia\\Model\\FeatureProduct', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'FeatureProducts'); $this->addRelation('ProductSaleElements', '\\Thelia\\Model\\ProductSaleElements', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'ProductSaleElementss'); diff --git a/local/config/schema.xml b/local/config/schema.xml index de1f058ef..d9305353f 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -49,7 +49,7 @@ - + diff --git a/setup/thelia.sql b/setup/thelia.sql index 100e8fd3b..369ae3cde 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -63,7 +63,7 @@ CREATE TABLE `product` FOREIGN KEY (`brand_id`) REFERENCES `brand` (`id`) ON UPDATE RESTRICT - ON DELETE RESTRICT + ON DELETE SET NULL ) ENGINE=InnoDB; -- --------------------------------------------------------------------- diff --git a/setup/update/2.0.3.sql b/setup/update/2.0.3.sql index 1e029fded..cd465fd61 100644 --- a/setup/update/2.0.3.sql +++ b/setup/update/2.0.3.sql @@ -118,18 +118,12 @@ CREATE TABLE `brand` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `visible` TINYINT, - `title` VARCHAR(255), - `description` LONGTEXT, - `chapo` TEXT, - `postscriptum` TEXT, - `meta_title` VARCHAR(255), - `meta_description` TEXT, - `meta_keywords` TEXT, + `position` INTEGER, `logo_image_id` INTEGER, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `fk_brand_brand_image1_idx` (`logo_image_id`), + INDEX `fk_brand_brand_image_idx` (`logo_image_id`), CONSTRAINT `fk_logo_image_id_brand_image` FOREIGN KEY (`logo_image_id`) REFERENCES `brand_image` (`id`) @@ -149,10 +143,6 @@ CREATE TABLE `brand_document` `brand_id` INTEGER NOT NULL, `file` VARCHAR(255) NOT NULL, `position` INTEGER, - `title` VARCHAR(255), - `description` LONGTEXT, - `chapo` TEXT, - `postscriptum` TEXT, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), @@ -176,15 +166,10 @@ CREATE TABLE `brand_image` `brand_id` INTEGER NOT NULL, `file` VARCHAR(255) NOT NULL, `position` INTEGER, - `title` VARCHAR(255), - `description` LONGTEXT, - `chapo` TEXT, - `postscriptum` TEXT, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), INDEX `idx_brand_image_brand_id` (`brand_id`), - INDEX `idx_brand_image_brand_id_is_brand_logo` (`brand_id`), CONSTRAINT `fk_brand_image_brand_id` FOREIGN KEY (`brand_id`) REFERENCES `brand` (`id`) @@ -192,6 +177,71 @@ CREATE TABLE `brand_image` ON DELETE CASCADE ) ENGINE=InnoDB; +-- --------------------------------------------------------------------- +-- brand_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `brand_i18n`; + +CREATE TABLE `brand_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255), + `description` LONGTEXT, + `chapo` TEXT, + `postscriptum` TEXT, + `meta_title` VARCHAR(255), + `meta_description` TEXT, + `meta_keywords` TEXT, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `brand_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `brand` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- brand_document_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `brand_document_i18n`; + +CREATE TABLE `brand_document_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255), + `description` LONGTEXT, + `chapo` TEXT, + `postscriptum` TEXT, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `brand_document_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `brand_document` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- brand_image_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `brand_image_i18n`; + +CREATE TABLE `brand_image_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255), + `description` LONGTEXT, + `chapo` TEXT, + `postscriptum` TEXT, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `brand_image_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `brand_image` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; -- --------------------------------------------------------- -- Add brand field to product table, and related constraint.