[Dbix-class] Per the design of a method

Oleg Kostyuk cub.uanic at gmail.com
Thu Jun 16 19:57:15 GMT 2011


I think, this should do what you want (untested):

my $rs = $db->resultset('Employee::Job')->search(
   { period => '2010-02-28' },
   { rows => 100 } # note, there is no OFFSET
);

my $your_rs = $rs->page(2); # same as you had with OFFSET
my $objects = [$rs->page(2)->all()]; # just for example: you will get
your objects
my $total_count = $rs->pager()->total_entries(); # your magic "2003"
number, I hope :)


But even if not, here is fallback:

my $rs = $db->resultset('Employee::Job')->search({ period => '2010-02-28' });
my $total_count = $rs->count;
my $your_rs = $rs->search(
   undef,
   {
       rows => 100,
       offset => 100,
   }
);

# here you will have $your_rs and $total_count

HTH, but if not, then re-read manuals :)



2011/6/16 dorian taylor <dorian.taylor.lists at gmail.com>:
> On Thu, Jun 16, 2011 at 10:17 AM, Peter Rabbitson <rabbit+dbic at rabbit.us> wrote:
>
>> This won't be wrong - ->count returns how many objects you would receive
>> via ->all/->next. If you want full count of the underlying source with
>> all limits removed - keep the original resultset around. If you do not care
>> about WHERE conditions either - $rs->result_source->resultset->count will
>> do it for you.
>
> Except it is wrong:
>
> my $rs = $db->resultset('Employee::Job')->search(
>    { period => '2010-02-28' },
>    {
>        rows => 100,
>        offset => 100,
>    }
> );
>
> print $rs->count; # 100, the number I'm looking for is 2023
>
> So what it looks like I want to do is like you suggested, clone the
> ResultSet and either get the WHERE clause out of the original or
> remove the rows/offset attributes and/or add them in later. I just
> don't see anything in the class's interface that will let me do that.
>
> Thanks,
>
> --
> Dorian Taylor
> http://doriantaylor.com/
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



-- 
Sincerely yours,
Oleg Kostyuk (CUB-UANIC)



More information about the DBIx-Class mailing list