man DBIx::Class::ResultSet () - Responsible for fetching and creating resultset.

NAME

DBIx::Class::ResultSet - Responsible for fetching and creating resultset.

SYNOPSIS

my CW$rs = MyApp::DB::Class->search(registered => 1); my CW@rows = MyApp::DB::Class->search(foo => 'bar');

DESCRIPTION

The resultset is also known as an iterator. It is responsible for handling queries that may return an arbitrary number of rows, e.g. via CWsearch or a CWhas_many relationship.

METHODS

new($db_class, \%$attrs)

The resultset constructor. Takes a table class and an attribute hash (see below for more information on attributes). Does not perform any queries these are executed as needed by the other methods.

cursor

Return a storage-driven cursor to the given resultset. Returns a subset of elements from the resultset.

next

Returns the next element in the resultset (undef is there is none).

count

Performs an SQL CWCOUNT with the same query as the resultset was built with to find the number of elements.

all

Returns all elements in the resultset. Called implictly if the resultset is returned in list context.

reset

Resets the resultset's cursor, so you can iterate through the elements again.

first

Resets the resultset and returns the first element.

delete

Deletes all elements in the resultset.

pager

Returns a Data::Page object for the current resultset. Only makes sense for queries with page turned on.

page($page_num)

Returns a new resultset for the specified page.

Attributes

The resultset takes various attributes that modify its behavior. Here's an overview of them:

order_by

Which column(s) to order the results by. This is currently passed through directly to SQL, so you can give e.g. CWfoo DESC for a descending order.

cols

Which columns should be retrieved.

join

Contains a list of relationships that should be joined for this query. Can also contain a hash reference to refer to that relation's relations. So, if one column in your class CWbelongs_to foo and another CWbelongs_to bar, you can do CWjoin => [qw/ foo bar /] to join both (and e.g. use them for CWorder_by). If a foo contains many margles and you want to join those too, you can do CWjoin => { foo => 'margle' }. If you want to fetch the columns from the related table as well, see CWprefetch below.

prefetch

Contains a list of relationships that should be fetched along with the main query (when they are accessed afterwards they will have already been prefetched). This is useful for when you know you will need the related object(s), because it saves a query. Currently limited to prefetching one relationship deep, so unlike CWjoin, prefetch must be an arrayref.

from

This attribute can contain a arrayref of elements. Each element can be another arrayref, to nest joins, or it can be a hash which represents the two sides of the join.

NOTE: Use this on your own risk. This allows you to shoot your foot off!

page

For a paged resultset, specifies which page to retrieve. Leave unset for an unpaged resultset.

rows

For a paged resultset, how many rows per page