On Dec 11, 2007, at 12:16 PM, Cedric Boudin wrote:

I've been trying to push out of my C::Classes all this resutset stuff
that I rather see in the DBIx classes where they belong.
What did I do:

------------------
2)In the Myapp::M::Db.pm file where I configure the DBix connection
stuff I added
-------------------------------
package CatalEgo::M::CatalEgoDb;
++use base 'Catalyst::Model::Adaptor';

__PACKAGE__->config(
   schema_class => 'CatalEgo::Db',
   connect_info => [

       'dbi:Pg:dbname=.....',
       'USER,
       'passwd',

   ],
);
++__PACKAGE__->config( class => 'CatalEgo::Db' );


If you take the configuration out of the model, then you need to put it somewhere else in order to be able to use it...

Is it possible just to glue my whole DBIx::Model in one go into catalyst
so that I can use it as I use it as standalone outside the catalkyst
environment.

Yes, and if your requirement is just to be able to use your DBIx::Class classes without Catalyst, then you don't even need Catalyst::Model::Adapter, you just need to move the configuration stuff into the database class...

This is how I do it...

# The database main class
package MyApp::DB;
use base qw( DBIx::Class );
__PACKAGE__->load_classes();
__PACKAGE__->connection(
        'DBI:Pg:dbname=...',
        'user', 'password',
        { AutoCommit => 1 },
);
1;

# The catalyst model
package MyApp::Web::Model::DB;
use base qw( Catalyst::Model::DBIC::Schema );
__PACKAGE__->config( schema_class => 'MyApp::DB' );
1;


This way, any other code that needs to use it can, just by doing:
use MyApp::DB;

my $schema = MyApp::DB->connect;

If you don't want the username and password to be hardcoded into the script, you can still do the same thing, but other code that needs to use it will have to pass the authentication information when calling - >connect.

--
Jason Kohles, RHCA RHCDS RHCE
[EMAIL PROTECTED] - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire



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

Reply via email to