Begin paged list of books on author page.
This commit is contained in:
parent
3c2dd9eac5
commit
e2748bd642
|
@ -31,8 +31,13 @@ sub authors ($self) {
|
|||
|
||||
sub author ($self) {
|
||||
my $id = $self->param('id');
|
||||
my ($author, $book_page) = MyModel::Author->new(
|
||||
rows_per_page => $self->rpp
|
||||
)->find_by_id($id);
|
||||
$self->render(
|
||||
author => MyModel::Author->new->find_by_id($id)
|
||||
author => $author,
|
||||
book_page => $book_page,
|
||||
pager => $book_page->pager,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,16 @@ sub get_page ($self, $page_number = 1, $name_like = undef) {
|
|||
return $rs;
|
||||
}
|
||||
|
||||
sub find_by_id ($self, $id) {
|
||||
return $self->schema->resultset('Author')->find(
|
||||
{ id => $id },
|
||||
{ prefetch => [ "books" ] },
|
||||
sub find_by_id ($self, $id, $page_number = 1) {
|
||||
my $author = $self->schema->resultset('Author')->find({ id => $id });
|
||||
my $book_page = $author->books_rs->search(
|
||||
undef,
|
||||
{ order_by => [ "me.title" ],
|
||||
page => $page_number,
|
||||
rows => $self->rows_per_page,
|
||||
},
|
||||
);
|
||||
return ($author, $book_page);
|
||||
}
|
||||
|
||||
no Moose;
|
||||
|
|
|
@ -5,3 +5,17 @@
|
|||
<strong><%= $author->name %></strong>
|
||||
% my $count = $author->books->count;
|
||||
wrote <%= $count %> book<%= "s" if ($count > 1) %>.
|
||||
|
||||
<p/>
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
</tr>
|
||||
% for my $book ($book_page->all) {
|
||||
<tr>
|
||||
<td><%= $book->title %></td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue