[Catalyst] DBIx relationships
Peter Edwards
peter at dragonstaff.com
Sat Dec 8 09:12:45 GMT 2007
Angel,
I'd recommend working through the tutorial, it explains many things
http://search.cpan.org/~jrockway/Catalyst-Manual-5.701003/lib/Catalyst/Manua
l/Tutorial.pod
Looking at your code, on each iteration with $line in $rs->next you are
setting the entire body, overwriting whatever you put in the previous time.
So you end up only showing the last row found. Something like this would
show all the lines
$c->response->body( $c->response->body . $line->first_name . "\n" );
In practice you put DBIC objects like $rs in the stash and call DBIC methods
on them from inside your TT templates.
In the tutorial in the controller:
http://search.cpan.org/~jrockway/Catalyst-Manual-5.701003/lib/Catalyst/Manua
l/Tutorial/CatalystBasics.pod#CREATE_A_CATALYST_CONTROLLER
$c->stash->{books} = [$c->model('MyAppDB::Book')->all];
And then further down the tutorial inside the template:
http://search.cpan.org/~jrockway/Catalyst-Manual-5.701003/lib/Catalyst/Manua
l/Tutorial/CatalystBasics.pod#Create_a_TT_Template_Page
[% FOREACH book IN books -%]
<tr>
<td>[% book.title %]</td>
<td>[% book.rating %]</td>
...
</tr>
[% END -%]
Subscribe to the DBIx::Class user and developer list at
http://lists.scsys.co.uk/mailman/listinfo/dbix-class
DBIC documentation map at
http://search.cpan.org/~blblack/DBIx-Class-0.07006/lib/DBIx/Class/Manual/Doc
Map.pod
Regards, Peter
http://perl.dragonstaff.co.uk <http://perl.dragonstaff.co.uk/>
________________________________________
From: Angel Kolev [mailto:ankolev at gmail.com]
Sorry but im just badly stucked at this :(
I want to iterate using the model
my $rs = $c->model('AppModelDB::ClientMale')->search();
while (my $line = $rs->next) {
$c->response->body($line->first_name);
}
The result is always one name. I need all fields them to put them in TT
template.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071208/69e99800/attachment-0001.htm
More information about the Catalyst
mailing list