Re: [Catalyst] Accessing schema in non-DBIC-model

2008-07-19 Thread Matt S Trout
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 Directorhttp://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/

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Accessing schema in non-DBIC-model

2008-07-01 Thread Tobias Kremer
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

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/