From 1b4e7ebf9ea2e59166547895a3a3955d0d50d634 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 14 Sep 2015 17:05:53 +0100 Subject: [PATCH] Bug 14819: Add missing DBIx::Class relationships - biblio<->biblioitem<->item To access the biblio from an item, we should not use the biblioitemnumber relationship autogenerated by DBIx::Class::Schema::Loader but create our own one. Test plan: Confirm the tests pass and that there is no regression on bug 14726. --- Koha/Item.pm | 9 +++++++ Koha/Schema/Result/Biblioitem.pm | 2 +- Koha/Schema/Result/Item.pm | 2 ++ .../prog/en/modules/circ/circulation.tt | 2 +- t/db_dependent/Schema.t | 31 ++++++++++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 t/db_dependent/Schema.t diff --git a/Koha/Item.pm b/Koha/Item.pm index 2dcccfb..4d311f6 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -37,6 +37,15 @@ Koha::Item - Koha Item object class =cut +=head3 biblioitem + +=cut + +sub biblioitem { + my ( $self ) = @_; + return $self->_result->biblioitem; +} + =head3 effective_itemtype Returns the itemtype for the item based on whether item level itemtypes are set or not. diff --git a/Koha/Schema/Result/Biblioitem.pm b/Koha/Schema/Result/Biblioitem.pm index 874f1d2..a9b926a 100644 --- a/Koha/Schema/Result/Biblioitem.pm +++ b/Koha/Schema/Result/Biblioitem.pm @@ -344,6 +344,6 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-02-24 14:19:57 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:A/4lKYlKWWd8TcMVzMRtCg +__PACKAGE__->belongs_to( biblio => "Koha::Schema::Result::Biblio", "biblionumber" ); -# You can replace this text with custom content, and it will be preserved on regeneration 1; diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index c342f46..2f764a3 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -619,6 +619,8 @@ __PACKAGE__->might_have( # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-04-23 12:42:12 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:urSpNt7LBda4T5Plhi6cPw +__PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" ); + sub effective_itemtype { my ( $self ) = @_; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 6d9e5ad..1b7558a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -675,7 +675,7 @@ No patron matched [% message %] [% IF ( issue ) %]
-

Checked out: [% issue.item.biblioitemnumber.biblionumber.title %] ([% issue.item.barcode %]). Due on [% issue.date_due | $KohaDates %]

+

Checked out: [% issue.item.biblioitem.biblio.title %] ([% issue.item.barcode %]). Due on [% issue.date_due | $KohaDates %]

[% END %] diff --git a/t/db_dependent/Schema.t b/t/db_dependent/Schema.t new file mode 100644 index 0000000..b4f0347 --- /dev/null +++ b/t/db_dependent/Schema.t @@ -0,0 +1,31 @@ +use Modern::Perl; +use Test::More tests => 1; + +use t::lib::TestBuilder; + +use Koha::Biblios; +use Koha::Items; + +my $builder = t::lib::TestBuilder->new; + +subtest 'item->biblioitem' => sub { + plan tests => 1; + + # NOTE This is a trick, if we want to populate the biblioitems table, we should not create a Biblio but a Biblioitem + my $biblio = $builder->build( { source => 'Biblioitem', } )->{_fk}{biblionumber}; + my $item1 = $builder->build( + { source => 'Item', + value => { biblionumber => $biblio->{biblionumber}, biblioitemnumber => $biblio->{biblionumber} }, + } + ); + my $item2 = $builder->build( + { source => 'Item', + value => { biblionumber => $biblio->{biblionumber}, biblioitemnumber => $biblio->{biblionumber} }, + } + ); + + my $biblio_object = Koha::Biblios->find( $biblio->{biblionumber} ); + my $item_object = Koha::Items->find( $item1->{itemnumber} ); + + is( $item_object->biblioitem->biblio->biblionumber, $biblio->{biblionumber} ); +}; -- 2.1.0