[Catalyst] Accessing schema in non-DBIC-model

Tobias Kremer list at funkreich.de
Tue Jul 1 13:49:37 BST 2008


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



More information about the Catalyst mailing list