[Catalyst] iterating ResultSet in controller vs. template

Yuval Kogman nothingmuch at woobling.org
Tue Jun 19 22:22:29 GMT 2007

On Tue, Jun 19, 2007 at 12:58:10 -0400, John Goulah wrote:

If you do this:

>    my $myalums  = $c->model('MyDB::Alumni')->search({}, { rows => 20 }) ;

Then change this:

>   [% FOREACH alum IN alumni -%]

Into this:

	[% FOREACH alum IN alumni.all -%]

This gives you two big advantages IMHO:

	1. you can put resultset on the stash without paying for them
	with an SQL query. If the view chooses not to use this resultset
	(due to user prefs, feed variant, whatever) then the DB is never
	queried. This is easier to maintain and comes at a small
	performance overhead in comparison to making these decisions in
	the controller.

	2. subsequent actions can further filter the data set, or use it
	to create related resultsets. This encourages code reuse.

  Yuval Kogman <nothingmuch at woobling.org>
http://nothingmuch.woobling.org  0xEBD27418

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070620/72ad9d83/attachment.pgp

More information about the Catalyst mailing list