View | Details | Raw Unified | Return to bug 16965
Collapse All | Expand All

(-)a/Koha/Objects.pm (-12 / +14 lines)
Lines 142-160 Searches the specified relationship, optionally specifying a condition and attri Link Here
142
sub search_related {
142
sub search_related {
143
    my ( $self, $rel_name, @params ) = @_;
143
    my ( $self, $rel_name, @params ) = @_;
144
144
145
    return if !$rel_name;
145
    if (wantarray) {
146
    if (wantarray) {
146
        my @dbic_rows = $self->_resultset()->search_related($rel_name, @params);
147
        my @dbic_rows = $self->_resultset()->search_related($rel_name, @params);
147
        my $object_class = get_object_class( $dbic_rows[0]->result_class )->[1];
148
        return if !@dbic_rows;
149
        my $object_class = _get_objects_class( $dbic_rows[0]->result_class );
148
150
149
        eval "require $object_class";
151
        eval "require $object_class";
150
        return $object_class->_wrap(@dbic_rows);
152
        return _wrap( $object_class, @dbic_rows );
151
153
152
    } else {
154
    } else {
153
        my $rs = $self->_resultset()->search_related($rel_name, @params);
155
        my $rs = $self->_resultset()->search_related($rel_name, @params);
154
        my $object_class = get_object_class( $rs->result_class )->[1];
156
        return if !$rs;
157
        my $object_class = _get_objects_class( $rs->result_class );
155
158
156
        eval "require $object_class";
159
        eval "require $object_class";
157
        return $object_class->_new_from_dbic($rs);
160
        return _new_from_dbic( $object_class, $rs );
158
    }
161
    }
159
}
162
}
160
163
Lines 242-257 sub _resultset { Link Here
242
    }
245
    }
243
}
246
}
244
247
245
sub get_object_class {
248
sub _get_objects_class {
246
    my ( $type ) = @_;
249
    my ( $type ) = @_;
247
    return unless $type;
250
    return unless $type;
248
    $type =~ s|^Koha::Schema::Result::||;
251
249
    my $mappings = {
252
    if( $type->can('koha_objects_class') ) {
250
        Branch => [ qw( Koha::Library Koha::Libraries ) ],
253
        return $type->koha_objects_class;
251
        Borrower => [ qw( Koha::Patron Koha::Patrons ) ],
254
    }
252
        OldIssue => [ qw( Koha::OldIssue Koha::OldIssues ) ],
255
    $type =~ s|Schema::Result::||;
253
    };
256
    return "${type}s";
254
    return $mappings->{$type};
255
}
257
}
256
258
257
=head3 columns
259
=head3 columns
(-)a/Koha/Schema/Result/Borrower.pm (+4 lines)
Lines 1253-1256 __PACKAGE__->belongs_to( Link Here
1253
    { borrowernumber => "guarantorid" },
1253
    { borrowernumber => "guarantorid" },
1254
);
1254
);
1255
1255
1256
sub koha_objects_class {
1257
    'Koha::Patrons';
1258
}
1259
1256
1;
1260
1;
(-)a/Koha/Schema/Result/Branch.pm (-1 / +5 lines)
Lines 533-536 __PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode"); Link Here
533
533
534
534
535
# You can replace this text with custom code or comments, and it will be preserved on regeneration
535
# You can replace this text with custom code or comments, and it will be preserved on regeneration
536
537
sub koha_objects_class {
538
    'Koha::Libraries';
539
}
540
536
1;
541
1;
537
- 

Return to bug 16965