From: Arthur Axel "fREW" Schmidt Date: Wed, 7 Oct 2009 18:31:02 +0000 (+0000) Subject: is_paginated method and test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=305ce558b4dd7c9737e78d4921abea054c5162b4;p=dbsrgits%2FDBIx-Class-Historic.git is_paginated method and test --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 45e838f..9f628b2 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -519,7 +519,7 @@ sub find { # in ::Relationship::Base::search_related (the row method), and furthermore # the relationship is of the 'single' type. This means that the condition # provided by the relationship (already attached to $self) is sufficient, - # as there can be only one row in the databse that would satisfy the + # as there can be only one row in the databse that would satisfy the # relationship } else { @@ -1240,7 +1240,7 @@ sub _count_rs { my $tmp_attrs = { %$attrs }; - # take off any limits, record_filter is cdbi, and no point of ordering a count + # take off any limits, record_filter is cdbi, and no point of ordering a count delete $tmp_attrs->{$_} for (qw/select as rows offset order_by record_filter/); # overwrite the selector (supplied by the storage) @@ -2564,6 +2564,17 @@ sub clear_cache { shift->set_cache(undef); } +=head2 is_paginated + +Returns true if the resultset has been paginated + +=cut + +sub is_paginated { + my ($self) = @_; + return !!$self->{attrs}{page}; +} + =head2 related_resultset =over 4 @@ -2711,8 +2722,8 @@ sub _chain_relationship { }]; my $seen = { %{$attrs->{seen_join} || {} } }; - my $jpath = ($attrs->{seen_join} && keys %{$attrs->{seen_join}}) - ? $from->[-1][0]{-join_path} + my $jpath = ($attrs->{seen_join} && keys %{$attrs->{seen_join}}) + ? $from->[-1][0]{-join_path} : []; @@ -2948,7 +2959,7 @@ sub _resolved_attrs { # even though it doesn't make much sense, this is what pre 081xx has # been doing if (my $page = delete $attrs->{page}) { - $attrs->{offset} = + $attrs->{offset} = ($attrs->{rows} * ($page - 1)) + ($attrs->{offset} || 0) @@ -3143,7 +3154,7 @@ These are in no particular order: =back -Which column(s) to order the results by. +Which column(s) to order the results by. [The full list of suitable values is documented in L; the following is a summary of @@ -3435,12 +3446,12 @@ exactly as you might expect. =over 4 -=item * +=item * Prefetch uses the L to populate the prefetched relationships. This may or may not be what you want. -=item * +=item * If you specify a condition on a prefetched relationship, ONLY those rows that match the prefetched condition will be fetched into that relationship. diff --git a/t/resultset/is_paginated.t b/t/resultset/is_paginated.t new file mode 100644 index 0000000..df423ff --- /dev/null +++ b/t/resultset/is_paginated.t @@ -0,0 +1,19 @@ +use strict; +use warnings; + +use lib qw(t/lib); +use Test::More; +use Test::Exception; +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $tkfks = $schema->resultset('Artist'); + +ok !$tkfks->is_paginated, 'vanilla resultset is not paginated'; + +my $paginated = $tkfks->search(undef, { page => 5 }); +ok $paginated->is_paginated, 'resultset is paginated now'; + +done_testing; +