[Dbix-class] So they want ME to give a presentationaboutDBIx::Class

Octavian Rasnita octavian at fcc.ro
Fri Jan 29 18:35:52 GMT 2010


From: "Ihnen, David" <dihnen at amazon.com>
Good point, especially for an introduction... why to use an ORM.
I'll have to spin up myself a bit on Template Toolkit (I'd been using 
HTML::Template previously) and will probably have to merely mention rather 
than explore the FormMu stuff, as I've never worked in Catalyst.
David

You can tell them that they can use a resultset in a template directly like:
[% IF users != 0 -%]

[% WHILE (user = users.next) -%]
  [% user.id %] [% user.name %]

  [% blogs = user.blogs_rs -%]
  [% WHILE (blog = blogs.next) -%]
    [% blog.title %]

    [% articles = blog.articles_rs -%]
    [% WHILE (article = articles.next) -%]
      [% article.title %] [% article.body %]
    [% END -%]
  [% END -%]
[% END -%]

[% END -%]

And that loop of loops executes an SQL query only if the resultset "users" 
contains elements. Some of the conditions may not have a relation with the 
database and the user could use [% IF something == "ok" %], and if the var 
`something` won't be equal to "ok", then no SQL query will be executed.

Of course, using this way, the designer will be able to print something like

[% user.password %] or [% user.another_private_info %]

and the programmers might not want to allow the designers of the templates 
to have that freedom, but if this is not an issue, it is a very helpful way 
of using DBIC.

Octavian




More information about the DBIx-Class mailing list