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

Matt S Trout dbix-class at trout.me.uk
Fri Jan 25 13:11:35 GMT 2008


On Fri, Jan 25, 2008 at 01:07:49PM +0100, Tobias Kremer wrote:
> Quoting Matt S Trout <dbix-class at trout.me.uk>:
> > On Fri, Jan 25, 2008 at 10:13:38AM +0100, Tobias Kremer wrote:
> > > Quoting Matt S Trout <dbix-class at trout.me.uk>:
> > > > # 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.
> > >
> > > Thanks, Matt! I'd be happy to write up a small doc patch for this.
> > > Maybe in a new section "Model Caching" in Catalyst::Manual::Cookbook?
> >
> > I'd've thought it belongs in Model::DBIC::Schema
> > perhaps along with some stuff about using ACCEPT_CONTEXT to apply
> > RestrictWithObject too ...
> 
> I haven't used RestrictWithObject yet. Are you thinking of something
> along the lines of what Jonathan does here (only with Model::DBIC::Schema):
> 
> http://git.jrock.us/?p=doqueue.git;a=blob;f=lib/DoQueue/Model/DBIC/Restricted.pm;h=bfc2e66adb9322ed5105f9560d4ea2dc527c809e;hb=f67e9aecf50e9935955ce7872dc1c56caa6bfdaf

Yes, except using Catalyst::Component::InstancePerContext so it still
behaves like a normal DBIC::Schema (i.e. you copy and modify ->schema)

-- 
      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