FAQ
I'm using Catalyst::Model::DBIC::Schema to make my DBIC schema available as
model in my Catalyst application. Now I'd like to create a custom model (e.g.
MyApp::Model::Custom) which during the server start fetches and calculates some
stuff from the database via my DBIC schema and keeps it in the object to speed
up retrieval in my Cat app. I want to do:

my $rs = $c->model( 'Custom' )->find_by_foo( $foo )

and get back a (e.g. MyApp::Schema::Foo) ResultSet with stuff fetched during
server start that fits the condition $foo.

My problem is that I can't think of an elegant way to access the initialized
schema from within the models new or COMPONENT method (which is called during
server start when the model is set up). I tried this:

sub COMPONENT {
my( $class, $app, $args ) = @_;
$app->model( 'Schema::Foo' )->result_source->schema ...
}

But, of course, $app->model('Schema::Foo') isn't fully initialized at that time.

Any hint is greatly appreciated!

--Tobias

Search Discussions

  • Matt S Trout at Jul 20, 2008 at 1:36 am

    On Tue, Jul 01, 2008 at 02:49:37PM +0200, Tobias Kremer wrote:
    I'm using Catalyst::Model::DBIC::Schema to make my DBIC schema available as
    model in my Catalyst application. Now I'd like to create a custom model (e.g.
    MyApp::Model::Custom) which during the server start fetches and calculates some
    stuff from the database via my DBIC schema and keeps it in the object to speed
    up retrieval in my Cat app. I want to do:

    my $rs = $c->model( 'Custom' )->find_by_foo( $foo )

    and get back a (e.g. MyApp::Schema::Foo) ResultSet with stuff fetched during
    server start that fits the condition $foo.

    My problem is that I can't think of an elegant way to access the initialized
    schema from within the models new or COMPONENT method (which is called during
    server start when the model is set up). I tried this:

    sub COMPONENT {
    my( $class, $app, $args ) = @_;
    $app->model( 'Schema::Foo' )->result_source->schema ...
    }

    But, of course, $app->model('Schema::Foo') isn't fully initialized at that time.

    Any hint is greatly appreciated!
    Catalyst initializes less-namespaced names first.

    So I suspect if you called this MyApp::Model::Schema::Precache then
    $c->model('Schema')->resultset('Foo') would be fine.

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJul 1, '08 at 1:47p
activeJul 20, '08 at 1:36a
posts2
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Matt S Trout: 1 post Tobias Kremer: 1 post

People

Translate

site design / logo © 2022 Grokbase