|
Lines 57-68
sub new {
Link Here
|
| 57 |
|
57 |
|
| 58 |
if ($attributes) { |
58 |
if ($attributes) { |
| 59 |
$self->{_result} = |
59 |
$self->{_result} = |
| 60 |
Koha::Database->new()->schema()->resultset( $class->type() ) |
60 |
Koha::Database->new()->schema()->resultset( $class->_type() ) |
| 61 |
->new($attributes); |
61 |
->new($attributes); |
| 62 |
} |
62 |
} |
| 63 |
|
63 |
|
| 64 |
croak("No type found! Koha::Object must be subclassed!") |
64 |
croak("No _type found! Koha::Object must be subclassed!") |
| 65 |
unless $class->type(); |
65 |
unless $class->_type(); |
| 66 |
|
66 |
|
| 67 |
bless( $self, $class ); |
67 |
bless( $self, $class ); |
| 68 |
|
68 |
|
|
Lines 81-91
sub _new_from_dbic {
Link Here
|
| 81 |
# DBIC result row |
81 |
# DBIC result row |
| 82 |
$self->{_result} = $dbic_row; |
82 |
$self->{_result} = $dbic_row; |
| 83 |
|
83 |
|
| 84 |
croak("No type found! Koha::Object must be subclassed!") |
84 |
croak("No _type found! Koha::Object must be subclassed!") |
| 85 |
unless $class->type(); |
85 |
unless $class->_type(); |
| 86 |
|
86 |
|
| 87 |
croak( "DBIC result type " . ref( $self->{_result} ) . " isn't of the type " . $class->type() ) |
87 |
croak( "DBIC result _type " . ref( $self->{_result} ) . " isn't of the _type " . $class->_type() ) |
| 88 |
unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->type(); |
88 |
unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->_type(); |
| 89 |
|
89 |
|
| 90 |
bless( $self, $class ); |
90 |
bless( $self, $class ); |
| 91 |
|
91 |
|
|
Lines 230-236
sub _result {
Link Here
|
| 230 |
|
230 |
|
| 231 |
# If we don't have a dbic row at this point, we need to create an empty one |
231 |
# If we don't have a dbic row at this point, we need to create an empty one |
| 232 |
$self->{_result} ||= |
232 |
$self->{_result} ||= |
| 233 |
Koha::Database->new()->schema()->resultset( $self->type() )->new({}); |
233 |
Koha::Database->new()->schema()->resultset( $self->_type() )->new({}); |
| 234 |
|
234 |
|
| 235 |
return $self->{_result}; |
235 |
return $self->{_result}; |
| 236 |
} |
236 |
} |
|
Lines 279-292
sub AUTOLOAD {
Link Here
|
| 279 |
return; |
279 |
return; |
| 280 |
} |
280 |
} |
| 281 |
|
281 |
|
| 282 |
=head3 type |
282 |
=head3 _type |
| 283 |
|
283 |
|
| 284 |
This method must be defined in the child class. The value is the name of the DBIC resultset. |
284 |
This method must be defined in the child class. The value is the name of the DBIC resultset. |
| 285 |
For example, for borrowers, the type method will return "Borrower". |
285 |
For example, for borrowers, the _type method will return "Borrower". |
| 286 |
|
286 |
|
| 287 |
=cut |
287 |
=cut |
| 288 |
|
288 |
|
| 289 |
sub type { } |
289 |
sub _type { } |
| 290 |
|
290 |
|
| 291 |
sub DESTROY { } |
291 |
sub DESTROY { } |
| 292 |
|
292 |
|