Skip to content

Commit

Permalink
clarify result_class attribute of ResultSet objects
Browse files Browse the repository at this point in the history
This expands on Perl5#21 to add similar documentation to the ResultSet class
itself, explaining how the accessor method differs in behavior from the
attributes passed in to the search() method.
  • Loading branch information
preaction committed Nov 19, 2016
1 parent 7db2873 commit 3ff9e12
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/DBIx/Class/ResultClass/HashRefInflator.pm
Expand Up @@ -34,14 +34,22 @@ from a massive resultset, while skipping the creation of fancy result objects.
Specifying this class as a C<result_class> for a resultset will change C<< $rs->next >>
to return a plain data hash-ref (or a list of such hash-refs if C<< $rs->all >> is used).
There are two ways of applying this class to a resultset:
There are three ways of applying this class to a resultset:
=over
=item *
Specify C<< $rs->result_class >> on a specific resultset to affect only that
resultset (and any chained off of it); or
Specify C<< $rs->result_class >> on a specific resultset to affect only
that resultset object (if you are going to immediately call C<find>,
C<next>, C<all>, or another result method).
=item *
Specify C<< $rs->search({}, { result_class => '...' }) >> to affect this
resultset and any further resultset objects created from this one. Use
this if you are chaining additional calls to C<search> and want the final
results to be hash-refs.
=item *
Expand Down
11 changes: 11 additions & 0 deletions lib/DBIx/Class/ResultSet.pm
Expand Up @@ -1546,6 +1546,11 @@ that were originally loaded in the source class via
L<load_components|Class::C3::Componentised/load_components( @comps )>.
Any overloaded methods in the original source class will not run.
Setting the result_class with this method will change the class only for
this resultset instance. Setting the result_class using the C<search>
C<%attrs> hash will change the class for this resultset and any
resultset chained from this resultset.
=cut

sub result_class {
Expand Down Expand Up @@ -4665,6 +4670,12 @@ Set to 'update' for a SELECT ... FOR UPDATE or 'shared' for a SELECT
... FOR SHARED. If \$scalar is passed, this is taken directly and embedded in the
query.
=head2 result_class
Set the result_class attribute for this resultset and any resultset chained
from this resultset. This differs from using the L</result_class> accessor:
The accessor is not chained and only applies to the current resultset.
=head1 PREFETCHING
DBIx::Class supports arbitrary related data prefetching from multiple related
Expand Down

0 comments on commit 3ff9e12

Please sign in to comment.