From: Tomas Cohen Arazi Date: Fri, 12 Apr 2019 16:46:04 +0000 (-0300) Subject: Bug 22700: Make biblio_metadata prefetchable from Koha::Biblio X-Git-Tag: v19.05.00~345 X-Git-Url: http://git.equinoxoli.org/?p=koha.git;a=commitdiff_plain;h=0e762da67092e8bd04e37908e9e1419ea16f70e3 Bug 22700: Make biblio_metadata prefetchable from Koha::Biblio This patch makes $biblio->metadata be prefetchable as the Coding guidelines require. A new has_one relationship is added in the Biblio schema, named as the accessor to also convey to proposed guidelines for readability. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Koha/Biblio.t => SUCCESS: No regressions! - Sign off :-D Signed-off-by: Michal Denar Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 56f9185..48a585a 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -74,9 +74,8 @@ Returns a Koha::Biblio::Metadata object sub metadata { my ( $self ) = @_; - $self->{_metadata} ||= Koha::Biblio::Metadatas->find( { biblionumber => $self->id } ); - - return $self->{_metadata}; + my $metadata = $self->_result->metadata; + return Koha::Biblio::Metadata->_new_from_dbic($metadata); } =head3 subtitles diff --git a/Koha/Schema/Result/Biblio.pm b/Koha/Schema/Result/Biblio.pm index 53e806b..c262326 100644 --- a/Koha/Schema/Result/Biblio.pm +++ b/Koha/Schema/Result/Biblio.pm @@ -366,4 +366,11 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ebn7Szfm8/HbrdAc7ekTnA +__PACKAGE__->has_one( + "metadata", + "Koha::Schema::Result::BiblioMetadata", + { "foreign.biblionumber" => "self.biblionumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + 1;