LunarCowgirl has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing many-to-many relationships in Catalyst
by Your Mother (Archbishop) on Aug 24, 2014 at 02:06 UTC | |
by LunarCowgirl (Sexton) on Aug 25, 2014 at 02:57 UTC |