[Israel.pm] Class::DBI
Yuval Yaari
yuval at windax.com
Wed Mar 16 13:56:25 PST 2005
Yona Shlomo wrote:
>Hello,
>
>I want to write a module that inherits from Class::DBI.
>Problem:
> I have some "object" (read: tables) in database A
> that refer to some other "objects" (read: tables) in database B
>Question:
> 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( ... );
1;
package A::Table;
use base 'A::DBI';
A::Table->table('table_name');
A::Table->columns(All => qw/id a b c d/);
1;
package B::DBI;
use base 'Class::DBI';
# Different connection than A::DBI...
B::DBI->connection( ... );
1;
package B::Table;
use base 'B::DBI';
B::Table->table('table_name');
B::Table->columns(All => qw/id e f g h/);
B::Table->has_a(something => 'A::Table');
1;
# 8< --------------------------
I hope it helps...
I didn't try this, so I can't promise you that it'd work...
--Yuval
More information about the Perl
mailing list