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> _______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ Searchable Archive: http://www.mail-archive.com/[email protected]/
