Re: CDBI::Pager and has_many
[prev]
[thread]
[next]
[Date index for 2004/09/02]
Rhesa, Thanks for the patch.
Applied and new version of Class::DBI::Pager 0.06 is now going onto CPAN.
The URL
http://bulknews.net/lib/archives/Class-DBI-Pager-0.06.tar.gz
has entered CPAN as
file: $CPAN/authors/id/M/MI/MIYAGAWA/Class-DBI-Pager-0.06.tar.gz
size: 3897 bytes
md5: 358429211e6264779d37834ecf728ac1
Here's a changelog
0.06 Thu Sep 2 21:30:55 JST 2004
* Fixed problem with has_many()
(Thanks to Rhesa Rozendaal)
On Thu, 02 Sep 2004 14:10:25 +0200
Rhesa Rozendaal <perl@xxxxx.xxx> wrote:
> Rhesa Rozendaal wrote:
>
> > Hi!
> >
> > Is there a way to have the Pager work with has_many relationships?
> > I'm trying to do:
> >
> > my $cd = CD->retrieve(1);
> > my $pager = $cd->pager;
> > my $tracks = $pager->tracks;
> >
> > in order to page through the tracks for a specific CD, but it doesn't
> > seem to return Tracks. It's returning CD's instead, which is a pity.
> > What's happening internally is that CDBI is retrieving the correct
> > records, but the Pager is converting them to the CD class.
>
> Since nobody responded yet, I took the plunge and tried to fix this
> myself. Surprisingly simple. Here's a patch for the interested:
>
> --- Pager.pm 2004-09-02 13:28:02.083051200 +0200
> +++ My\Pager.pm 2004-09-02 13:28:28.380865600 +0200
> @@ -51,8 +51,7 @@
> my $pager = $self->{pager} = Data::Page->new(
> $iter->count, $self->{entry}, $self->{curr},
> );
> - my @data = ($iter->data)[$pager->first-1 .. $pager->last-1];
> - return $self->{pkg}->_ids_to_objects(\@data);
> + return $iter->slice($pager->first-1 , $pager->last-1);
> }
> else {
> _croak(qq(Can't locate object method "$method" via package ) .
> ref($self) || $self);
>
>
> I'll submit this to the original author with additional tests.
>
> Regards,
>
> Rhesa
>
>
--
Tatsuhiko Miyagawa <miyagawa@xxxxxxxx.xx>