[Catalyst] One result / Multiple results
David Naughton
naughton at umn.edu
Mon May 30 07:22:34 CEST 2005
Chisel,
Whew! That's a lot of detail. Much of it doesn't seem related to the
problem, and I don't have time to read all your code, but one thing
sticks out that doesn't make sense:
[% FOR a_list = one_result.data.list %]a:[% a_list.name %]#
[% END %]
Both "one_result" and "multiple" are CDBI Iterators, so why not this
instead?
[% WHILE (a_list = one_result.next) %] ... [% END %]
If I'm missing something, please try to describe your problem much more
simply.
HTH!
David Naughton
On Mon, May 30, 2005 at 01:37:32AM +0100, Chisel Wright wrote:
> I've got a really simple app, which I'm just using to fine tune some
> ideas, and maybe some documentation.
>
> I've got myself confused with looping over some results.
>
> I have a very simple (postgres) table:
>
> ---- cut here ----
> CREATE TABLE foo (
> foo_id SERIAL primary key NOT NULL,
> name text NOT NULL,
> description text
> );
> -- a couple of entries
> insert into foo (name, description) values ('Mr Fluffy', 'My fluffy Foo');
> insert into foo (name, description) values ('Spike', 'My spiky Foo');
> ---- cut here ----
>
> and a controller Foo, with
>
> ---- cut here ----
> sub list : Local {
> my ( $self, $c ) = @_;
> my ($criteria, $order_by);
>
> # the template to show
> $c->stash->{'template'} = 'foo/testing.tt';
>
> # fetch all the records from the database
> $c->stash->{'one_result'} = FooBar::M::FooDB::Foo->search_like(
> 'name' => 'M%',
> );
>
> $c->stash->{'multiple'} = FooBar::M::FooDB::Foo->search_like(
> 'name' => '%',
> );
>
> use Data::Dumper;
> $c->log->debug( 'One Result: ', Dumper $c->stash->{'one_result'} );
> $c->log->debug( 'Multiple: ', Dumper $c->stash->{'multiple'} );
> }
> ---- cut here ----
>
> foo/testing.tt looks pretty simple:
> ---- cut here ----
> [% FOR a_list = one_result.data.list %]a:[% a_list.name %]#
> [% END %]
>
> [% FOR b_list = multiple.data.list %]b:[% b_list.name %]#
> [% END %]
> ---- cut here ----
>
> For some reason the output from this is:
>
> ---- cut here ----
> <!-- TIMER START: process foo/testing.tt -->
> a:#
> a:#
> a:#
>
>
> b:Mr Fluffy#
> b:Spike#
>
>
> <!-- TIMER END: process foo/testing.tt (0.001548 seconds) -->
> ---- cut here ----
>
> but I really can't see why. The dumper output looks like this:
> ---- cut here ----
> [Mon May 30 01:32:05 2005] [catalyst] [debug] One Result:
> bless( {
> '_data' => [
> {
> 'name' => 'Mr Fluffy',
> 'foo_id' => '1',
> 'description' => 'My fluffy Foo'
> }
> ],
> '_place' => 0,
> '_mapper' => [],
> '_class' => 'FooBar::M::FooDB::Foo'
> }, 'Class::DBI::Iterator' )
>
> [Mon May 30 01:32:05 2005] [catalyst] [debug] Multiple:
> bless( {
> '_data' => [
> {
> 'name' => 'Mr Fluffy',
> 'foo_id' => '1',
> 'description' => 'My fluffy Foo'
> },
> {
> 'name' => 'Spike',
> 'foo_id' => '2',
> 'description' => 'My spiky Foo'
> }
> ],
> '_place' => 0,
> '_mapper' => [],
> '_class' => 'FooBar::M::FooDB::Foo'
> }, 'Class::DBI::Iterator' )
> ---- cut here ----
>
> which, apart from the number of items in _data look the same to me.
>
> Any idea what I'm missing here? Is there a way to print a "dump" of
> something in TT? I can't see how to show what three objects a_list
> thinks it has in it.
>
> I'm seeing the same behaviour with retrieve_all() too.
>
> [code attached if it's any use to anyone out there]
>
> Chisel
> --
> Chisel Wright
> e: chisel at herlpacker.co.uk
> w: http://www.herlpacker.co.uk/
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
More information about the Catalyst
mailing list