[Dbix-class] [PATCH] Slicing a paged ResultSet defies my
expectations
Matt S Trout
dbix-class at trout.me.uk
Sat Mar 8 16:14:30 GMT 2008
On Sat, Feb 23, 2008 at 10:22:18PM -0800, Ryan D Johnson wrote:
> Slicing a paged ResultSet does not do what I expected:
>
> $ my $files = $schema->resultset('File');
> $ $files = $files->search( undef, { rows => 5 } );
> $ $files = $files->page( 3 );
> $ my $count = $files->count;
> 5
> $ map { $_->id } $files->all;
> $ARRAY1 = [
> 13,
> 14,
> 15,
> 16,
> 17
> ];
> $ map { $_->id } $files->slice( $count-1, $count-1 );
> 9
>
> I would have expected '17', since it was the last item of the
> ResultSet in question.
>
> After reading the source, I became convinced that this was not by
> design. The slice method was querying $self->{attr}{offset}, which was
> bypassing the offset applied by the page. The new (sliced) ResultSet
> retained the page attribute of the old ResultSet, which didn't seem
> right either.
>
> I've attached a simple patch which aims to fix the two issues above,
> which also happens to bring the behavior back within my expectation.
> If '17' shouldn't be the answer to the last line in my re.pl output,
> let's straighten me out and perhaps I can instead patch the POD.
>
> The patch currently only touches the core file. I'm hoping to get some
> guidance about the appropriate place to put tests for this issue.
> Existing tests all pass except POD coverage (not related to my
> change).
We've caught up on IRC and discussed this.
Ryan, shout here when you've got progress to report please.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the DBIx-Class
mailing list