[Catalyst] Accessing $schema in Model glue class (solved?)

Matt S Trout dbix-class at trout.me.uk
Fri Jan 25 07:15:29 GMT 2008


On Thu, Jan 24, 2008 at 05:31:59PM +0100, Tobias Kremer wrote:
> Quoting Tobias Kremer <list at funkreich.de>:
> > Realizing that MyApp::Model::Schema is already just a subclass of
> > C::M::DBIC::Schema (doh!) I came up with the following solution that just
> > overrides new():
> 
> Hmmm ... Could somebody take a look at the following version I came up with
> and tell me if using Urbia2->cache (from Catalyst::Plugin::Cache::Memcached)
> in this context is okay:
> 
> # in MyApp::Model::Schema (which ISA Catalyst::Model::DBIC::Schema)
> sub new {
>   my $self = shift->NEXT::new(@_);
    my ($app, $config) = @_;
>   $self->schema->default_resultset_attributes( {
      cache_object => $app->cache
>   } );
>   return $self;
> }

Above is going to be more easily reusable.

The Takkle setup (for which Cursor::Cached was originally written, thanks
to them for sponsoring my work on it) also checks a $app->config key to
decide whether to use the app cache so we can keep sessions in memcache
but use Cache::Null for the DBIC stuff during testing.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list