if ($attributes) {
$self->{_result} =
- Koha::Database->new()->schema()->resultset( $class->type() )
+ Koha::Database->new()->schema()->resultset( $class->_type() )
->new($attributes);
}
- croak("No type found! Koha::Object must be subclassed!")
- unless $class->type();
+ croak("No _type found! Koha::Object must be subclassed!")
+ unless $class->_type();
bless( $self, $class );
# DBIC result row
$self->{_result} = $dbic_row;
- croak("No type found! Koha::Object must be subclassed!")
- unless $class->type();
+ croak("No _type found! Koha::Object must be subclassed!")
+ unless $class->_type();
- croak( "DBIC result type " . ref( $self->{_result} ) . " isn't of the type " . $class->type() )
- unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->type();
+ croak( "DBIC result _type " . ref( $self->{_result} ) . " isn't of the _type " . $class->_type() )
+ unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->_type();
bless( $self, $class );
If the object previously existed, it will be updated.
Returns:
- 1 if the store was a success
- 0 if the store failed
+ $self if the store was a success
+ undef if the store failed
=cut
sub store {
my ($self) = @_;
- return $self->_result()->update_or_insert() ? 1 : 0;
+ return $self->_result()->update_or_insert() ? $self : undef;
}
=head3 $object->in_storage();
}
}
- return $self->_result()->set_columns($properties) ? 1 : undef;
+ return $self->_result()->set_columns($properties) ? $self : undef;
}
=head3 $object->id();
return $id;
}
+=head3 $object->unblessed();
+
+Returns an unblessed representation of object.
+
+=cut
+
+sub unblessed {
+ my ($self) = @_;
+
+ return { $self->_result->get_columns };
+}
+
=head3 $object->_result();
Returns the internal DBIC Row object
# If we don't have a dbic row at this point, we need to create an empty one
$self->{_result} ||=
- Koha::Database->new()->schema()->resultset( $self->type() )->new({});
+ Koha::Database->new()->schema()->resultset( $self->_type() )->new({});
return $self->{_result};
}
# Using direct setter/getter like $item->barcode() or $item->barcode($barcode);
if ( grep {/^$method$/} @columns ) {
if ( @_ ) {
- return $self->_result()->set_column( $method, @_ );
+ $self->_result()->set_column( $method, @_ );
+ return $self;
} else {
my $value = $self->_result()->get_column( $method );
return $value;
return;
}
-=head3 type
+=head3 _type
This method must be defined in the child class. The value is the name of the DBIC resultset.
-For example, for borrowers, the type method will return "Borrower".
+For example, for borrowers, the _type method will return "Borrower".
=cut
-sub type { }
+sub _type { }
sub DESTROY { }