DBIx::Class::ResultSet - Responsible for fetching and creating resultset.
my $rs = MyApp::DB::Class->search(registered => 1); my @rows = MyApp::DB::Class->search(foo => 'bar');
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 search or a has_many relationship.
search
has_many
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.
Return a storage-driven cursor to the given resultset.
Returns a subset of elements from the resultset.
Returns the next element in the resultset (undef is there is none).
Performs an SQL COUNT with the same query as the resultset was built with to find the number of elements.
COUNT
Returns all elements in the resultset. Called implictly if the resultset is returned in list context.
Resets the resultset's cursor, so you can iterate through the elements again.
Resets the resultset and returns the first element.
Deletes all elements in the resultset.
Returns a Data::Page object for the current resultset. Only makes sense for queries with page turned on.
Returns a new resultset for the specified page.
The resultset takes various attributes that modify its behavior. Here's an overview of them:
Which column(s) to order the results by. This is currently passed through directly to SQL, so you can give e.g. foo DESC for a descending order.
foo DESC
Which columns should be retrieved.
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 belongs_to foo and another belongs_to bar, you can do join => [qw/ foo bar /] to join both (and e.g. use them for order_by). If a foo contains many margles and you want to join those too, you can do join => { foo => 'margle' }. If you want to fetch the columns from the related table as well, see prefetch below.
belongs_to
join => [qw/ foo bar /]
order_by
join => { foo => 'margle' }
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 join, prefetch must be an arrayref.
join
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!
For a paged resultset, specifies which page to retrieve. Leave unset for an unpaged resultset.
For a paged resultset, how many rows per page
To install DBIx::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class
CPAN shell
perl -MCPAN -e shell install DBIx::Class
For more information on module installation, please visit the detailed CPAN module installation guide.