FAQ
I struggled with this for way too long, and finally asked for some help on
#catalyst. mst dished out some wisdom there that I've captured into a stub
that could be a starting point for a cookbook recipe:




When you have data that you want to load just once from the model at server
load instead of for each request, use mk_group_accessors to create accessors
and tie them to resultsets in your package that inherits from
DBIx::Class::Schema

package My::Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->register_class('RESULTSOURCEMONIKER',
'My::Schema::RESULTSOURCE');

__PACKAGE__->mk_group_accessors('simple' => qw(ACCESSORNAME1
ACCESSORNAME2 ACCESSORNAMEn));

sub connection {
my ($self, @rest) = @_;
$self->next::method(@rest);

# $self is now a live My::Schema object, complete with DB connection


$self->ACCESSORNAME1([ $self->resultset('RESULTSOURCEMONIKER')->all
]);
$self->ACCESSORNAME2([
$self->resultset('RESULTSOURCEMONIKER')->search({ COLUMN => { '<' => '30' }
})->all ]);
$self->ACCESSORNAMEn([
$self->resultset('RESULTSOURCEMONIKER')->find(1) ]);
}

1;

and now in the controller, you can now access any of these without a
per-request fetch:

$c->stash->{something} = $c->model('My::Schema')->schema->ACCESSORNAMEn;




Comments?

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedAug 22, '07 at 9:58p
activeAug 22, '07 at 9:58p
posts1
users1
websitecatalystframework.org
irc#catalyst

1 user in discussion

Bits: 1 post

People

Translate

site design / logo © 2021 Grokbase