logo       

FOREACH Issue with DBIC and TT: msg#00119

Subject: FOREACH Issue with DBIC and TT
I was talking to some folks on #dbix-class today about an issue I'm
running into with FOREACH loops across a relationship between tables
with TT v2.15+, so I thought I would put together an example of what
I'm seeing.  My original question pertained to a has_many relationship
and this example uses a many-to-many, but the result appears to be the
same.

To recreate the issue, grab the code from the "CatalystBasics"
tutorial (this should obviously all be on one line):

svn co 
http://dev.catalyst.perl.org/repos/Catalyst/tags/examples/Tutorial/MyApp/5.7/CatalystBasics
CatalystBasics

Next, replace CatalystBasics/root/src/books/list.tt2 with the code at
the bottom of this note.

Then run the app:
cd CatalystBasics/
perl script/myapp_server.pl

And hit it with your browser at http://localhost:3000/books/list

When I'm running TT v2.14 it looks fine (the BAD and OK columns show
the same thing).  However, when I run it with TT v2.15, 2.16, 2.17 or
2.18, the books with only one author do not print anything.  Note that
the difference between the two columns is the sort vmethod -- without
sort it works.

Anyone have an idea whats going on?  I'll keep looking at it, but
given the various DBIC/TT issues that have been discussed in the past,
I thought someone else out there might know the answer (or have some
recommendations).

Thanks,
Kennedy

~~~~~~~

[% USE Dumper(Indent=1) %]
[% # Provide a title to root/lib/site/header -%]
[% META title = 'Book List' -%]
<table>
<tr><th>Title</th><th>Rating</th><th>Authors - BAD</th><th>Authors -
OK</th></tr>
[% # Display each book in a table row %]
[% FOREACH book = books.sort('title').reverse -%]
 <tr>
   <td>[% book.title %]</td>
   <td>[% book.rating %]</td>
   <td>
       BAD:
       [% FOREACH auth = book.authors.list.sort('last_name') %]
           [%# Remove comment below to dump %]
           [%# "<pre>"; Dumper.dump(auth); "</pre>" %]
           [% auth.last_name %]
       [% END %]
   </td>
   <td>
       OK:
       [% FOREACH auth = book.authors %]
           [% auth.last_name %]
       [% END %]
   </td>
 </tr>
[% END -%]
</table>



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
audio.irate.dev...    yellowdog.gener...    ietf.ips/2002-0...    xfree86.fonts/2...    busybox/2003-07...    emacs.jdee/2004...    linux.mandrake....    hardware.microc...    user-groups.lin...    science.analysi...    version-control...    db.filemaker.de...    cluster.openmos...    mail.eyebrowse....    text.xml.xerces...    kde.devel.kwrit...    finance.moneyda...    gcc.regression/...    network.routing...    os.freebsd.deve...    recreation.radi...    qnx.openqnx.dev...    python.xml/2002...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe