[Catalyst] work with second database

Fernan Aguero fernan at iib.unsam.edu.ar
Wed Apr 11 20:29:08 GMT 2007

+----[ Michael Higgins <mhiggins at banfieldgroup.com> (11.Apr.2007 16:08):
| Hello, All --
| As I'm still trying to get my head around the Catalyst way of doing things,
| I'm hoping can someone give me a hint:
| I have an application set up to report on a database. So far, so good. 
| Now, I've got another database I need to query. How do I best integrate
| access to it into my existing application?
create another model.

are you using dbix::class?

in my application's 'lib' directory I have:

# DB1 is mapped through the model1 schema
... more tables in this db

# DB2 is mapped through the model2 schema
... more tables in this db

Then in your controller´s code:

my $table1_model = $c->model('model1::Table1');
my $rs = $table1_model->search( { name => 'Me' });
my $cust = $rs->first->customer;

my $othermodel = $c->model('model2::AnotherTable');
my $rs2 = $othermodel-search( { customer => $cust });

Of course, you won't be able to do joins across the two


| Sorry for the generality of the question, but I don't even know the
| terminology yet. Is this, say, going to be a 'separate namespace' or
| something?
| Is there an example out there I could familiarize myself with, where a
| Catalyst application uses two different databases?
| I understand I can have as many models, views and controllers as I need. I
| don't understand what I need to create in order to have another model
| accessed from an existing controller, or how to define that model and get it
| loaded.
| Any leg up greatly appreciated.
| Cheers,
| -- 
| Michael Higgins
| _______________________________________________
| List: Catalyst at lists.rawmode.org
| Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
| Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
| Dev site: http://dev.catalyst.perl.org/

More information about the Catalyst mailing list