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.


In reply to Re: Accessing many-to-many relationships in Catalyst by Your Mother
in thread Accessing many-to-many relationships in Catalyst by LunarCowgirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.