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 295-310 sub _resultset { Link Here
295
    }
298
    }
296
}
299
}
297
300
298
sub get_object_class {
301
sub _get_objects_class {
299
    my ( $type ) = @_;
302
    my ( $type ) = @_;
300
    return unless $type;
303
    return unless $type;
301
    $type =~ s|^Koha::Schema::Result::||;
304
302
    my $mappings = {
305
    if( $type->can('koha_objects_class') ) {
303
        Branch => [ qw( Koha::Library Koha::Libraries ) ],
306
        return $type->koha_objects_class;
304
        Borrower => [ qw( Koha::Patron Koha::Patrons ) ],
307
    }
305
        OldIssue => [ qw( Koha::OldIssue Koha::OldIssues ) ],
308
    $type =~ s|Schema::Result::||;
306
    };
309
    return "${type}s";
307
    return $mappings->{$type};
308
}
310
}
309
311
310
=head3 columns
312
=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