[Catalyst] One result / Multiple results
Chisel Wright
chisel at herlpacker.co.uk
Mon May 30 02:37:32 CEST 2005
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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FooBar.tar.gz
Type: application/x-tar-gz
Size: 4302 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20050530/36bc8951/FooBar.tar.bin
More information about the Catalyst
mailing list