<<

NAME

Koha::Objects - Koha Object set base class

SYNOPSIS

    use Koha::Objects;
    my @objects = Koha::Objects->search({ borrowernumber => $borrowernumber});

DESCRIPTION

This class must be subclassed.

API

Class Methods

Koha::Objects->new();

my $object = Koha::Objects->new();

Koha::Objects->_new_from_dbic();

my $object = Koha::Objects->_new_from_dbic( $resultset );

Koha::Objects->find();

Similar to DBIx::Class::ResultSet->find this method accepts: \%columns_values | @pk_values, { key => $unique_constraint, %attrs }? Strictly speaking, columns_values should only refer to columns under an unique constraint.

It returns undef if no results were found

my $object = Koha::Objects->find( { col1 => $val1, col2 => $val2 } ); my $object = Koha::Objects->find( $id ); my $object = Koha::Objects->find( $idpart1, $idpart2, $attrs ); # composite PK

Koha::Objects->find_or_create();

my $object = Koha::Objects->find_or_create( $attrs );

search

    # list context
    my @objects = Koha::Objects->search([$params, $attributes]);
    # scalar context
    my $objects = Koha::Objects->search([$params, $attributes]);
    while (my $object = $objects->next) {
        do_stuff($object);
    }

This instantiates the Koha::Objects class, and generates a resultset based on the query $params and $attributes that are passed (like in DBIC).

In list context it returns an array of Koha::Object objects. In scalar context it returns an iterator.

search_related

    my @objects = Koha::Objects->search_related( $rel_name, $cond?, \%attrs? );
    my $objects = Koha::Objects->search_related( $rel_name, $cond?, \%attrs? );

Searches the specified relationship, optionally specifying a condition and attributes for matching records.

delete

update

    my $objects = Koha::Objects->new; # or Koha::Objects->search
    $objects->update( $fields, [ { no_triggers => 0/1 } ] );

This method overloads the DBIC inherited one so if code-level triggers exist (through the use of an overloaded update or store method in the Koha::Object based class) those are called in a loop on the resultset.

If no_triggers is passed and true, then the DBIC update method is called directly. This feature is important for performance, in cases where no code-level triggers should be triggered. The developer will explicitly ask for this and QA should catch wrong uses as well.

filter_by_last_update

my $filtered_objects = $objects->filter_by_last_update

days exclusive from inclusive to inclusive

single

my $object = Koha::Objects->search({}, { rows => 1 })->single

Returns one and only one object that is part of this set. Returns undef if there are no objects found.

This is optimal as it will grab the first returned result without instantiating a cursor.

See: http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#Retrieve_one_and_only_one_row_from_a_resultset

Koha::Objects->next();

my $object = Koha::Objects->next();

Returns the next object that is part of this set. Returns undef if there are no more objects to return.

Koha::Objects->last;

my $object = Koha::Objects->last;

Returns the last object that is part of this set. Returns undef if there are no object to return.

empty

    my $empty_rs = Koha::Objects->new->empty;

Sets the resultset empty. This is handy for consistency on method returns (e.g. if we know in advance we won't have results but want to keep returning an iterator).

Koha::Objects->reset();

Koha::Objects->reset();

resets iteration so the next call to next() will start agein with the first object in a set.

Koha::Objects->as_list();

Koha::Objects->as_list();

Returns an arrayref of the objects in this set.

Koha::Objects->unblessed

Returns an unblessed representation of objects.

Koha::Objects->get_column

Return all the values of this set for a given column

Koha::Objects->TO_JSON

Returns an unblessed representation of objects, suitable for JSON output.

Koha::Objects->to_api

Returns a representation of the objects, suitable for API output .

attributes_from_api

    my $attributes = $objects->attributes_from_api( $api_attributes );

Translates attributes from the API to DBIC

from_api_mapping

    my $mapped_attributes_hash = $objects->from_api_mapping;

Attributes map from the API to DBIC

prefetch_whitelist

    my $whitelist = $object->prefetch_whitelist()

Returns a hash of prefetchable subs and the type it returns

Koha::Objects->_wrap

wraps the DBIC object in a corresponding Koha object

Koha::Objects->_resultset

Returns the internal resultset or creates it if undefined

columns

my @columns = Koha::Objects->columns

Return the table columns

AUTOLOAD

The autoload method is used call DBIx::Class method on a resultset.

Important: If you plan to use one of the DBIx::Class methods you must provide relevant tests in t/db_dependent/Koha/Objects.t Currently count, is_paged, pager, result_class, single and slice are covered.

_type

The _type method must be set for all child classes. The value returned by it should be the DBIC resultset name. For example, for holds, _type should return 'Reserve'.

object_class

This method must be set for all child classes. The value returned by it should be the name of the Koha object class that is returned by this class. For example, for holds, object_class should return 'Koha::Hold'.

AUTHOR

Kyle M Hall <kyle@bywatersolutions.com>

<<