DBIx::Class - Related Tables

Paul Makepeace paulm at paulm.com
Tue Oct 7 10:55:14 BST 2008


On Tue, Oct 7, 2008 at 10:10 AM, Minty <mintywalker at gmail.com> wrote:
> On Tue, Oct 7, 2008 at 9:03 AM, Dave Hodgkinson <davehodg at gmail.com> wrote:
>> Then what's the benefit of an ORM? (general question, not just to you :)
>
> Dunno about ORMs in general, but being able to pass a DBIx::Class
> object into a TT template and have the template query the various
> values and pull out the things they want seems like a big win.
>
> Especially the object chaining
>
> my $vars = { module => $db->resultset('Module')->single({  ...some
> criteria ...}) };
> $template->process('mytemplate.tt', $vars)
>
> [% module.author.email | html %]

One aspect, that befalls any abstraction system, is that you run into
a situation where a lot of work is being hidden behind a simple
interface.

Let's say you have a page where there's a lot of dependency on the
role of the account you're logged in as.

[% IF c.check_user_roles('superhero') OR c.check_user_roles('crime_fighter') %]

and other combinations peppered throughout your template, that's an
SQL query per invocation. I recently had to fix up a template that was
doing this by caching in local vars as the template was making over a
dozen role authorization calls like this!

Similarly, anything beyond a fairly trivial join can mean you're
hitting the db on _every accessor_. (One solution is to switch on
tracing and add prefetching.)

I agree with Andy, and it's a theme I've been bleating on about since
DBIC arrived :-) But then I'm not contributing patches so don't bleat
too loud (and I've gotten used to it somewhat over three years...)

P

> I'm not sure it's the best example - I'm thinking about where your
> tables are connected in the schema, which lets you query tables that
> can join the 'module' table simply by using . in the template.  Thus
> the above 'module' table would only contain an 'author_id' column, and
> the 'author' table would contain the 'email' column.
>
> <0.02>
> I have in the past been wary of ORMs where you spend all your time
> learning the implementation details and being comfortably numb about
> the underlying theory.
>
> DBIx::Class I've taken a strong liking to tho fwiw.  Like jquery, when
> the abstraction is done well, it makes a lot of things better/shorter.
> </0.02>
>


More information about the london.pm mailing list