Skip to content

Commit

Permalink
Clarify docs for ::ResultSet::OneRow
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Jul 14, 2015
1 parent 79e5372 commit d64e166
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Clarify docs for ::ResultSet::OneRow (Thanks for the tips Aran Deltac!)
(Closes GH#48)
- Add abstract to ::Row::JoinTable (Thanks Gregor Herrmann!)
(Closes GH#49)

Expand Down
24 changes: 20 additions & 4 deletions lib/DBIx/Class/Helper/ResultSet/OneRow.pm
Expand Up @@ -31,10 +31,26 @@ sub one_row { shift->search(undef, { rows => 1})->next }
=head1 DESCRIPTION
This component codifies a "more correct" version of
L<DBIx::Class::ResultSet/first>. Fundamentally the difference is that when you
use C<one_row> you are guaranteed to exhaust the underlying cursor; depending on
your database this can resolve weird issues.
This component codifies an alternate version of L<DBIx::Class::ResultSet/first>.
In practical use, C<first> allows a user to do something like the following:
my $rs = $schema->resultset('Foo')->search({ name => 'bar' });
my $first = $rs->first;
my @rest;
while (my $row = $rs->next) {
push @rest, $row
}
Problematically, if you call C<first> without the while loop afterwards B<and>
you got back more than one row, you are leaving a cursor open. Depending on
your database this could increase memory usage or cause errors with later
queries.
Fundamentally the difference is that when you use C<one_row> you are guaranteed
to exhaust the underlying cursor.
Generally speaking, unless you are doing something unusual, C<one_row> is a good
default.
=head1 METHODS
Expand Down

0 comments on commit d64e166

Please sign in to comment.