[Dbix-class] Relationships between tables of the same name across databases

clara resende clrrsnd at gmail.com
Thu Jul 4 14:17:20 GMT 2013


Hello,

I figured out how to setup relations across multiple MySQL databases,
however it does not seem to work when the table that I want to link to
exists in both databases (different tables, same name).

All my tables in the 'mydb' database have 'journal' counterparts with the
same name in the 'journaldb' database. Now sometimes I want to join between
tables from the two databases.

In my table schema files I prefix the database name, e.g. for the 'users'
table:

__PACKAGE__->table("mydb.users");

and

__PACKAGE__->table("journaldb.users");

and in the "Journaldb::Schema", I extend from the "Mydb::Schema":

extends 'Mydb::Schema';

Then, e.g., in the journaldb table schema I can create a relation like:

__PACKAGE__->belongs_to(
    mydb_users =3D> 'Mydb::Schema::Result::User',
    { 'foreign.id' =3D> 'self.user_id' },
);

This works fine if the table name in the mydb database does not also exist
in the journaldb database. But if the table name does exists in the
journaldb, then it always links to the table in the journaldb database
itself.

Is it at all possible to create such a relation?

Thanks,

Meindert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130704/7a1=
a7a8a/attachment.htm


More information about the DBIx-Class mailing list