Bug 13713: Remove useless constraints previously added
authorJonathan Druart <jonathan.druart@biblibre.com>
Mon, 7 Jul 2014 12:57:25 +0000 (14:57 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 19 Mar 2015 17:05:45 +0000 (14:05 -0300)
This patch removes the 3 constraints added by patch from bug 11518.
Having 1-n + 1-1 relations for the same field is a non-sense.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Added a follow-up for removing some unneeded code.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Koha/Schema/Result/Biblio.pm
Koha/Schema/Result/Item.pm
t/db_dependent/Items.t

index 5f2e399..b61086e 100644 (file)
@@ -331,10 +331,10 @@ __PACKAGE__->many_to_many("sets", "oai_sets_biblios", "set");
 # Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0//8OGf7OteNnwT03g4QsA
 
-__PACKAGE__->belongs_to(
-    "biblioitem",
-    "Koha::Schema::Result::Biblioitem",
-    { "foreign.biblionumber" => "self.biblionumber" }
-);
+sub biblioitem {
+    my ( $self ) = @_;
+    my @biblioitems = $self->biblioitems;
+    return $biblioitems[0];
+}
 
 1;
index 8ea22e3..c199685 100644 (file)
@@ -612,17 +612,11 @@ __PACKAGE__->might_have(
 # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-10-24 09:58:16
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2slVK/FjcRDiYLeufoOFQQ
 
-__PACKAGE__->belongs_to(
-    "biblio",
-    "Koha::Schema::Result::Biblio",
-    { "foreign.biblionumber" => "self.biblionumber" }
-);
-
-__PACKAGE__->belongs_to(
-  "biblioitem",
-  "Koha::Schema::Result::Biblioitem",
-  { biblioitemnumber => "biblioitemnumber" },
-);
+sub biblioitem {
+    my ( $self ) = @_;
+    my @biblioitems = $self->biblioitemnumber;
+    return $biblioitems[0];
+}
 
 sub effective_itemtype {
     my ( $self ) = @_;
index dfb1654..4f9ee41 100755 (executable)
@@ -215,8 +215,7 @@ subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
         }
     );
 
-    my $biblioitem = $biblio->biblioitem();
-    my ( $item ) = $biblioitem->items();
+    my ( $item ) = $biblio->biblioitem->items();
 
     C4::Context->set_preference( 'item-level_itypes', 0 );
     ok( $item->effective_itemtype() eq 'BIB_LEVEL', '$item->itemtype() returns biblioitem.itemtype when item-level_itypes is disabled' );