We would have to see your relationships to help, I think. Also this does not sound like a many_to_many situation to me. A book has_many chapters and has_many pages, as does the chapter. They each belong_to a chapter and a book. Many pages are not in many books.
Pseudo-ish code, three Result files: Book, Chapter, Page
package Book;
use parent "DBIx::Class::Core";
__PACKAGE__->table("book");
__PACKAGE__->add_columns(qw/ id title /);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many( chapters => "Chapter",
{ "foreign.book" => "self.id" } );
# Probably a belongs_to Author here...
1;
package Chapter;
use parent "DBIx::Class::Core";
__PACKAGE__->table("chapter");
__PACKAGE__->add_columns(qw/ id title num book /);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many( pages => "Page",
{ "foreign.chapter" => "self.id" } );
__PACKAGE__->belongs_to( book => "Book" );
1;
package Page;
use parent "DBIx::Class::Core";
__PACKAGE__->table("page");
__PACKAGE__->add_columns(qw/ id content chapter num /);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( book => "Chapter" );
1;
Then for TT2, [% page.chapter.book.title %]: [% page.chapter.num %]. And–
# Gets latest 10 results
while ( my $page = $rs->next ) {
my $book = sprintf( "%02d", $page->chapter->book->title ); # Bo
+ok number???
my $chapter = sprintf( "%02d", $page->chapter->num );
}
Note, I feel "position" or "order" (bad name for DB columns) is superior to "num." It is self-regulating if set-up right, like an array, if you remove an element (page or chapter) from the middle, all the others adjust. |