[Israel.pm] Class::DBI

Yuval Yaari yuval at windax.com
Wed Mar 16 13:56:25 PST 2005

Yona Shlomo wrote:

>I want to write a module that inherits from Class::DBI.
>	I have some "object" (read: tables) in database A
>	that refer to some other "objects" (read: tables) in database B
>	Can anyone suggest ways to get support to "multiple
>	databases" in this framework?
>	How can make has_a, has_many and the rest of the
>	bunch work as expected when I am working with more
>	than one database?

This Should Work (TM):

# 8< --------------------------
package A::DBI;
use base 'Class::DBI';

A::DBI->connection( ... );


package A::Table;
use base 'A::DBI';
A::Table->columns(All => qw/id a b c d/);


package B::DBI;
use base 'Class::DBI';

# Different connection than A::DBI...
B::DBI->connection( ... );


package B::Table;
use base 'B::DBI';

B::Table->columns(All => qw/id e f g h/);
B::Table->has_a(something => 'A::Table');


# 8< --------------------------

I hope it helps...
I didn't try this, so I can't promise you that it'd work...


More information about the Perl mailing list