=head1 NAME
-DBIX::Class::Recordset - Responsible for fetching and creating recordsets.
+DBIX::Class::ResultSet - Responsible for fetching and creating resultset.
=head1 SYNOPSIS;
=head1 DESCRIPTION
-The recordset is also know as an iterator.
+The resultset is also known as an iterator.
=head1 METHODS
=item new <db_class> <attrs>
-The recordset constructor. Takes a db class and an
+The resultset constructor. Takes a db class and an
attribute hash (see below for more info on attributes)
=cut
sub new {
- my ($it_class, $db_class, $attrs) = @_;
+ my ($class, $db_class, $attrs) = @_;
#use Data::Dumper; warn Dumper(@_);
- $it_class = ref $it_class if ref $it_class;
+ $class = ref $class if ref $class;
$attrs = { %{ $attrs || {} } };
my %seen;
$attrs->{cols} ||= [ map { "me.$_" } $db_class->_select_columns ];
$db_class->_relationships->{$pre}->{class}->_select_columns);
}
my $new = {
- class => $db_class,
+ source => $db_class,
cols => $attrs->{cols} || [ $db_class->_select_columns ],
cond => $attrs->{where},
from => $attrs->{from} || $db_class->_table_name,
count => undef,
pager => undef,
attrs => $attrs };
- bless ($new, $it_class);
+ bless ($new, $class);
$new->pager if ($attrs->{page});
return $new;
}
=item cursor
-Return a storage driven cursor to the given record set.
+Return a storage driven cursor to the given resultset.
=cut
sub cursor {
my ($self) = @_;
- my ($db_class, $attrs) = @{$self}{qw/class attrs/};
+ my ($source, $attrs) = @{$self}{qw/source attrs/};
if ($attrs->{page}) {
$attrs->{rows} = $self->pager->entries_per_page;
$attrs->{offset} = $self->pager->skipped;
}
return $self->{cursor}
- ||= $db_class->storage->select($self->{from}, $self->{cols},
+ ||= $source->storage->select($self->{from}, $self->{cols},
$attrs->{where},$attrs);
}
=item slice <first> <last>
-return a number of elements from the given record set.
+return a number of elements from the given resultset.
=cut
sub slice {
my ($self, $min, $max) = @_;
my $attrs = { %{ $self->{attrs} || {} } };
- $self->{class}->throw("Can't slice without where") unless $attrs->{where};
+ $self->{source}->throw("Can't slice without where") unless $attrs->{where};
$attrs->{offset} = $min;
$attrs->{rows} = ($max ? ($max - $min + 1) : 1);
- my $slice = $self->new($self->{class}, $attrs);
+ my $slice = $self->new($self->{source}, $attrs);
return (wantarray ? $slice->all : $slice);
}
=item next
-Returns the next element in this record set.
+Returns the next element in this resultset.
=cut
my ($self, @row) = @_;
my @cols = @{ $self->{attrs}{cols} };
s/^me\.// for @cols;
- @cols = grep { ! /\./ } @cols;
+ @cols = grep { /\(/ or ! /\./ } @cols;
my $new;
unless ($self->{attrs}{prefetch}) {
- $new = $self->{class}->_row_to_object(\@cols, \@row);
+ $new = $self->{source}->_row_to_object(\@cols, \@row);
} else {
my @main = splice(@row, 0, scalar @cols);
- $new = $self->{class}->_row_to_object(\@cols, \@main);
+ $new = $self->{source}->_row_to_object(\@cols, \@main);
PRE: foreach my $pre (@{$self->{attrs}{prefetch}}) {
- my $rel_obj = $self->{class}->_relationships->{$pre};
- my $pre_class = $self->{class}->resolve_class($rel_obj->{class});
+ my $rel_obj = $self->{source}->_relationships->{$pre};
+ my $pre_class = $self->{source}->resolve_class($rel_obj->{class});
my @pre_cols = $pre_class->_select_columns;
my @vals = splice(@row, 0, scalar @pre_cols);
my $fetched = $pre_class->_row_to_object(\@pre_cols, \@vals);
- $self->{class}->throw("No accessor for prefetched $pre")
+ $self->{source}->throw("No accessor for prefetched $pre")
unless defined $rel_obj->{attrs}{accessor};
if ($rel_obj->{attrs}{accessor} eq 'single') {
foreach my $pri ($rel_obj->{class}->primary_columns) {
} elsif ($rel_obj->{attrs}{accessor} eq 'filter') {
$new->{_inflated_column}{$pre} = $fetched;
} else {
- $self->{class}->throw("Don't know how to store prefetched $pre");
+ $self->{source}->throw("Don't know how to store prefetched $pre");
}
}
}
sub count {
my ($self) = @_;
- my $db_class = $self->{class};
my $attrs = { %{ $self->{attrs} } };
unless ($self->{count}) {
# offset and order by are not needed to count
delete $attrs->{$_} for qw/offset order_by/;
my @cols = 'COUNT(*)';
- $self->{count} = $db_class->storage->select_single($self->{from}, \@cols,
- $self->{cond}, $attrs);
+ $self->{count} = $self->{source}->storage->select_single(
+ $self->{from}, \@cols, $self->{cond}, $attrs);
}
return 0 unless $self->{count};
return $self->{pager}->entries_on_this_page if ($self->{pager});
=item all
-Returns all elements in the recordset. Is called implictly if the search
+Returns all elements in the resultset. Is called implictly if the search
method is used in list context.
=cut
=item reset
-Reset this recordset's cursor, so you can iterate through the elements again.
+Reset this resultset's cursor, so you can iterate through the elements again.
=cut
=item first
-resets the recordset and returns the first element.
+resets the resultset and returns the first element.
=cut
=item delete
-Deletes all elements in the recordset.
+Deletes all elements in the resultset.
=cut
=item page <page>
-Returns a new recordset representing a given page.
+Returns a new resultset representing a given page.
=cut
my ($self, $page) = @_;
my $attrs = $self->{attrs};
$attrs->{page} = $page;
- return $self->new($self->{class}, $attrs);
+ return $self->new($self->{source}, $attrs);
}
=back
=head1 Attributes
-The recordset is responsible for handling the various attributes that
+The resultset is responsible for handling the various attributes that
can be passed in with the search functions. Here's an overview of them:
=over 4