Re: CDBI::Pager and has_many
[prev]
[thread]
[next]
[Date index for 2004/09/02]
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
 |
 |
Re: CDBI::Pager and has_many
Rhesa Rozendaal 12:10 on 02 Sep 2004
|