From f5f34c3fc66172809353fbb096e03e0d06be0f41 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 Signed-off-by: Martin Renvoize --- Koha/Schema/Result/Item.pm | 16 +++++------- Koha/Schema/Result/ItemGroupItem.pm | 26 +++---------------- .../atomicupdate/bug_24857_item_groups.pl | 4 +-- installer/data/mysql/kohastructure.sql | 4 +-- 4 files changed, 14 insertions(+), 36 deletions(-) diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 6c421a329f..e0eccb3f8a 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 }, @@ -880,12 +880,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-01 12:37:33 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1mLs4vLD2LsJGkBKZCZbXg -======= -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-18 14:00:35 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WG9AuZsBgTMEWjlfwFQdeA ->>>>>>> Bug 24857: Rename Volumes => Item groups (DB) +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-01 12:52:33 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WeRY0B6a1D94WckYmUgWpQ __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" ); diff --git a/Koha/Schema/Result/ItemGroupItem.pm b/Koha/Schema/Result/ItemGroupItem.pm index 2ad0155f52..33a0939f4b 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,24 +129,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-01 12:37:33 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zfCA4diZgiexDnY1rD6xkQ - -=head2 koha_object_class - -=cut - -sub koha_object_class { - 'Koha::Biblio::Volume::Item'; -} - -=head2 koha_objects_class - -=cut -======= -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-18 14:00:35 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UkFl9MLWlH8wy3T/AaVIdQ ->>>>>>> Bug 24857: Rename Volumes => Item groups (DB):Koha/Schema/Result/ItemGroupItem.pm +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-01 12:52:33 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:y9cE5sPmUxcJFgAZfsEQsg 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 05fd10fef3..7be6496c72 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.20.1