Koha::Object - Koha Object base class
use Koha::Object; my $object = Koha::Object->new({ property1 => $property1, property2 => $property2, etc... } );
This class must always be subclassed.
my $object = Koha::Object->new(); my $object = Koha::Object->new($attributes);
Note that this cannot be used to retrieve record from the DB.
my $object = Koha::Object->_new_from_dbic($dbic_row);
Saves the object in storage. If the object is new, it will be created. If the object previously existed, it will be updated.
Returns: $self if the store was a success undef if the store failed
Removes the object from storage.
Returns: 1 if the deletion was a success 0 if the deletion failed -1 if the object was never in storage
$object->set( { property1 => $property1, property2 => $property2, property3 => $propery3, } );
Enables multiple properties to be set at once
Returns: 1 if all properties were set. 0 if one or more properties do not exist. undef if all properties exist but a different error prevents one or more properties from being set.
If one or more of the properties do not exist, no properties will be set.
Returns an unblessed representation of object.
Returns an unblessed representation of the object, suitable for JSON output.
my $object_for_api = $object->to_api( { [ embed => { items => { children => { holds => {, children => { ... } } } }, library => { ... } }, ... ] } );
Returns a representation of the object, suitable for API output.
my $mapping = $object->to_api_mapping;
Generic method that returns the attribute name mappings required to render the object on the API.
Note: this only returns an empty hashref. Each class should have its own mapping returned.
my $mapping = $object->from_api_mapping;
Generic method that returns the attribute name mappings so the data that comes from the API is correctly renamed to match what is required for the DB.
my $object = Koha::Object->new_from_api; my $object = Koha::Object->new_from_api( $attrs );
Creates a new object, mapping the API attribute names to the ones on the DB schema.
my $object = Koha::Object->new(...); $object->set_from_api( $attrs )
Sets the object's attributes mapping API attribute names to the ones on the DB schema.
my $attributes = attributes_from_api( $params );
Returns the passed params, converted from API naming into the model.
my $everything_into_one_hashref = $object->unblessed_all_relateds
The unblessed method only retrieves column' values for the column of the object. In a *few* cases we want to retrieve the information of all the prefetched data.
Returns the internal DBIC Row object
Returns an arrayref of the table columns
The autoload method is used only to get and set values for an objects properties.
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".
Kyle M Hall <kyle@bywatersolutions.com>
Jonathan Druart <jonathan.druart@bugs.koha-community.org>