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;
####
# Gets latest 10 results
while ( my $page = $rs->next ) {
my $book = sprintf( "%02d", $page->chapter->book->title ); # Book number???
my $chapter = sprintf( "%02d", $page->chapter->num );
}