}
else {
- my $class = ref( $self );
+ my $class = ref($self) ? ref($self) : $self;
my $rs = $self->_resultset()->search($params);
return $class->new_from_dbic($rs);
sub _resultset {
my ($self) = @_;
- $self->{_resultset} ||=
- Koha::Database->new()->schema()->resultset( $self->type() );
+ if ( ref($self) ) {
+ $self->{_resultset} ||=
+ Koha::Database->new()->schema()->resultset( $self->type() );
- $self->{_resultset};
+ return $self->{_resultset};
+ }
+ else {
+ return Koha::Database->new()->schema()->resultset( $self->type() );
+ }
}
=head3 type
);
$b3->store();
-my $b1_new = Koha::Borrowers->new()->find( $b1->borrowernumber() );
+my $b1_new = Koha::Borrowers->find( $b1->borrowernumber() );
is( $b1->surname(), $b1_new->surname(), "Found matching borrower" );
-my @borrowers = Koha::Borrowers->new()->search( { branchcode => $branchcode } );
+my @borrowers = Koha::Borrowers->search( { branchcode => $branchcode } );
is( @borrowers, 3, "Found 3 borrowers with Search" );
-my $borrowers = Koha::Borrowers->new()->search( { branchcode => $branchcode } );
+my $borrowers = Koha::Borrowers->search( { branchcode => $branchcode } );
is( $borrowers->count( { branchcode => $branchcode } ), 3, "Counted 3 borrowers with Count" );
my $b = $borrowers->next();