I'm sure the answer is probably simple, but I haven't yet stumbled onto it. I've been learning DBIx::Class with Catalyst. So far I've been able to figure out how they work together, but I'm stuck on one issue.

I have a many-to-many relationship that joins together three tables which are basically called "page", "chapter", and "book". I can gather resultsets and pass them into Template Toolkit, using them as such:

[% page.book.title %]: [% page.chapter.num %]

which prints out the title and chapter number of the book. My questions is: how can I do that within Catalyst itself? I'm setting up an RSS feed, and I need access to "page.book.num" and "page.chapter.num" to create a url within the feed. I've tried both variations below, as well as others:

# Gets latest 10 results my $rs = $c->model('DB::Page')->get_rss; while ( my $page = $rs->next ) { my $book = sprintf( "%02d", $page->book->{num} ); my $chapter = sprintf( "%02d", $page->chapter->num ); ... }

Neither of those work. The first returns "00". The second produces an error that "num" can't be found. Is there any simple way to do this?


In reply to 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.