Bugzilla – Attachment 53777 Details for
Bug 16965
Add the Koha::Objects->search_related method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16965: [Follow-up] Adjust get_object_class
Bug-16965-Follow-up-Adjust-getobjectclass.patch (text/plain), 3.36 KB, created by
Marcel de Rooy
on 2016-07-28 12:54:46 UTC
(
hide
)
Description:
Bug 16965: [Follow-up] Adjust get_object_class
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2016-07-28 12:54:46 UTC
Size:
3.36 KB
patch
obsolete
>From 5a22336e1769bc4fc6171d3fa0f66074f2fda79b Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 28 Jul 2016 14:28:43 +0200 >Subject: [PATCH] Bug 16965: [Follow-up] Adjust get_object_class >Content-Type: text/plain; charset=utf-8 > >In many cases it should be possible to derive the Koha::Objects class >name from the DBIx result class name in a trivial manner. >If not, the DBIx result class should have a class method called >koha_objects_class providing that non-trivial name, such as Libraries >for Branch. > >Note: We are only interested in the plural form here (Koha::Objects). > >Test plan: >Run t/db_dependent/Koha/Objects.t >--- > Koha/Objects.pm | 26 ++++++++++++++------------ > Koha/Schema/Result/Borrower.pm | 4 ++++ > Koha/Schema/Result/Branch.pm | 5 +++++ > 3 files changed, 23 insertions(+), 12 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index bb8629c..84bc54b 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -142,19 +142,22 @@ Searches the specified relationship, optionally specifying a condition and attri > sub search_related { > my ( $self, $rel_name, @params ) = @_; > >+ return if !$rel_name; > if (wantarray) { > my @dbic_rows = $self->_resultset()->search_related($rel_name, @params); >- my $object_class = get_object_class( $dbic_rows[0]->result_class )->[1]; >+ return if !@dbic_rows; >+ my $object_class = _get_objects_class( $dbic_rows[0]->result_class ); > > eval "require $object_class"; >- return $object_class->_wrap(@dbic_rows); >+ return _wrap( $object_class, @dbic_rows ); > > } else { > my $rs = $self->_resultset()->search_related($rel_name, @params); >- my $object_class = get_object_class( $rs->result_class )->[1]; >+ return if !$rs; >+ my $object_class = _get_objects_class( $rs->result_class ); > > eval "require $object_class"; >- return $object_class->_new_from_dbic($rs); >+ return _new_from_dbic( $object_class, $rs ); > } > } > >@@ -295,16 +298,15 @@ sub _resultset { > } > } > >-sub get_object_class { >+sub _get_objects_class { > my ( $type ) = @_; > return unless $type; >- $type =~ s|^Koha::Schema::Result::||; >- my $mappings = { >- Branch => [ qw( Koha::Library Koha::Libraries ) ], >- Borrower => [ qw( Koha::Patron Koha::Patrons ) ], >- OldIssue => [ qw( Koha::OldIssue Koha::OldIssues ) ], >- }; >- return $mappings->{$type}; >+ >+ if( $type->can('koha_objects_class') ) { >+ return $type->koha_objects_class; >+ } >+ $type =~ s|Schema::Result::||; >+ return "${type}s"; > } > > =head3 columns >diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm >index ecf39e9..805edbb 100644 >--- a/Koha/Schema/Result/Borrower.pm >+++ b/Koha/Schema/Result/Borrower.pm >@@ -1241,4 +1241,8 @@ __PACKAGE__->belongs_to( > { borrowernumber => "guarantorid" }, > ); > >+sub koha_objects_class { >+ 'Koha::Patrons'; >+} >+ > 1; >diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm >index 9d84ab9..b3e9e42 100644 >--- a/Koha/Schema/Result/Branch.pm >+++ b/Koha/Schema/Result/Branch.pm >@@ -533,4 +533,9 @@ __PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode"); > > > # You can replace this text with custom code or comments, and it will be preserved on regeneration >+ >+sub koha_objects_class { >+ 'Koha::Libraries'; >+} >+ > 1; >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16965
:
53656
|
53673
|
53777
|
56009
|
56010
|
56011
|
56238
|
56239
|
56240
|
56372
|
56373
|
56374
|
56375
|
56650
|
56651
|
56652
|
56653