On Tue, 1 Apr 2008, Alex Povolotsky wrote:
Sorry for resending, looks like everyone able to answer overlooked this
message. I'm researching the problem without much success.
After 1 day?? What sort of support contract do you have?
Hello!
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
information.
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' %]
<ul>
[% WHILE (p = parent.next) %]
parent [% p.name %] has [% p.children.count %] children,
This is TT. that .children is in list context, so .count will not be
called
(and TT will silently fail to tell you why)
Try p.children_rs.count.
<ol>
[% WHILE (child = p.children.next) %]
This will get you a new children list every time it loops so a) use
children_rs to get a resultset, not a list, and b) take that value and
stick it in a var, then call next on it.
<li> [% child.name %] has [% child.records.count %] records,
<ul>
[% WHILE (record = child.records.next) %]
Same again with child.records.
<li>[% record.message %]
[% END %]
</ul>
[% END %]
</ol>
[% END %]
</ul>
Output is disappointing
index
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'
with DBIC_TRACE.
Attempt to dump (using Plugin::Dumper) p.children yields reasonable result.
What am I doing wrong?
Posting to the wrong list.. I would have seen this if it were on the
dbix-class list..
OTOH, its a mix of TT, cat and DBIC so.. first you should have taken it
apart a piece at a time, to figure at which stage the problem was.
Then you would have found it yourself.
Jess
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/