From a24728aa6a53af932ea5376133787634575b8aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Mon, 23 Aug 2021 14:18:17 +0000 Subject: [PATCH] Bug 24857: item_group_items.item_id must be unique --- Koha/Schema/Result/Item.pm | 12 ++++++------ Koha/Schema/Result/ItemGroupItem.pm | 10 ++++------ .../data/mysql/atomicupdate/bug_24857_item_groups.pl | 4 ++-- installer/data/mysql/kohastructure.sql | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 4445e36e86..57f2938b66 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -729,16 +729,16 @@ __PACKAGE__->might_have( { cascade_copy => 0, cascade_delete => 0 }, ); -=head2 item_group_items +=head2 item_group_item -Type: has_many +Type: might_have Related object: L =cut -__PACKAGE__->has_many( - "item_group_items", +__PACKAGE__->might_have( + "item_group_item", "Koha::Schema::Result::ItemGroupItem", { "foreign.item_id" => "self.itemnumber" }, { cascade_copy => 0, cascade_delete => 0 }, @@ -865,8 +865,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-18 14:00:35 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WG9AuZsBgTMEWjlfwFQdeA +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-19 17:07:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sISORyGGTxgSHIXdkBbvlg __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" ); diff --git a/Koha/Schema/Result/ItemGroupItem.pm b/Koha/Schema/Result/ItemGroupItem.pm index 21699b5c44..0a84f8e303 100644 --- a/Koha/Schema/Result/ItemGroupItem.pm +++ b/Koha/Schema/Result/ItemGroupItem.pm @@ -84,19 +84,17 @@ __PACKAGE__->set_primary_key("item_group_items_id"); =head1 UNIQUE CONSTRAINTS -=head2 C +=head2 C =over 4 -=item * L - =item * L =back =cut -__PACKAGE__->add_unique_constraint("item_group_id", ["item_group_id", "item_id"]); +__PACKAGE__->add_unique_constraint("item_id", ["item_id"]); =head1 RELATIONS @@ -131,8 +129,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-18 14:00:35 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UkFl9MLWlH8wy3T/AaVIdQ +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-19 17:07:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IvIDQDpWchSS05iCGuZSvQ sub koha_object_class { 'Koha::Biblio::ItemGroup::Item'; diff --git a/installer/data/mysql/atomicupdate/bug_24857_item_groups.pl b/installer/data/mysql/atomicupdate/bug_24857_item_groups.pl index 07daba7bfa..c5e39f3088 100755 --- a/installer/data/mysql/atomicupdate/bug_24857_item_groups.pl +++ b/installer/data/mysql/atomicupdate/bug_24857_item_groups.pl @@ -39,9 +39,9 @@ use Modern::Perl; `item_group_id` INT(11) NOT NULL DEFAULT 0 COMMENT "foreign key making this table a 1 to 1 join from items to item groups", `item_id` INT(11) NOT NULL DEFAULT 0 COMMENT "foreign key linking this table to the items table", PRIMARY KEY (`item_group_items_id`), - UNIQUE KEY (item_group_id,item_id), + UNIQUE KEY (`item_id`), CONSTRAINT `item_group_items_iifk_1` FOREIGN KEY (`item_id`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `item_group_items_vifk_1` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `item_group_items_gifk_1` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; }); } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 2149682025..519b50c6ec 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1833,9 +1833,9 @@ CREATE TABLE `item_group_items` ( `item_group_id` INT(11) NOT NULL DEFAULT 0 COMMENT "foreign key making this table a 1 to 1 join from items to item groups", `item_id` INT(11) NOT NULL DEFAULT 0 COMMENT "foreign key linking this table to the items table", PRIMARY KEY (`item_group_items_id`), - UNIQUE KEY (item_group_id,item_id), + UNIQUE KEY (`item_id`), CONSTRAINT `item_group_items_iifk_1` FOREIGN KEY (`item_id`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `item_group_items_vifk_1` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `item_group_items_gifk_1` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- 2.30.2