[Catalyst] Nested calls to model does not work?

Alex Povolotsky tarkhil at over.ru
Tue Apr 1 11:14:40 BST 2008

Sorry for resending, looks like everyone able to answer overlooked this 
message. I'm researching the problem without much success.


I've experienced strange problem displaying data. Minimal test case is
fairly big, I can attach it here, but will try to extract most important

Creating database (Pg)

create table parent (pid serial primary key, name varchar(64));
create table child (cid serial primary key, pid int not null references
parent(pid), name varchar(64));
create table record (rid serial primary key, cid int not null references
child(cid), message varchar(64));
insert into parent (name) values('parent');
insert into child (pid, name) values (1, 'child');
insert into record (cid, message) values (1, 'message one');
insert into record (cid, message) values (1, 'message two');

creating model and view

script/testcase_create.pl model Main DBIC::Schema Testcase::Schema
create=static dbi:Pg:dbname=testcase testcase
script/testcase_create.pl view Main TTSite

in Root controller, writing trivial

sub index : Local {
    my ( $self, $c ) = @_;
    $c->stash->{parent} = $c->model('Main::Parent')->search();

in index template, everything is trivial as well

[% META title = 'index' %]
[% WHILE (p = parent.next) %]
parent [% p.name %] has [% p.children.count %] children,
   [% WHILE (child = p.children.next) %]
   <li> [% child.name %] has [% child.records.count %] records,
      [% WHILE (record = child.records.next) %]
         <li>[% record.message %]
      [% END %]
   [% END %]
[% END %]

Output is disappointing


   parent parent has children,

   © 2008 Your Name Here

while we get

SELECT me.pid, me.name FROM parent me:
SELECT me.cid, me.pid, me.name FROM child me WHERE ( me.pid = ? ): '1'
SELECT me.cid, me.pid, me.name FROM child me WHERE ( me.pid = ? ): '1'


Attempt to dump (using Plugin::Dumper) p.children yields reasonable result.

What am I doing wrong?


List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

More information about the Catalyst mailing list