[Dbix-class] Relationships spanning multiple databases
Matt S Trout
dbix-class at trout.me.uk
Thu Nov 23 18:26:02 GMT 2006
Sam Crawley wrote:
> Hi,
>
> I have two schemas connecting to two related databases. I'd like some
> way of "joining" between the two, i.e. to be able to do this:
>
> my $record = App::Schema1::RS->find(1);
>
> my $rec2 = $record->rec_from_schema2;
>
> Where $rec2 is something from Schema2, i.e. data from a different database.
>
> I thought I may be able to setup a relationship from one schema to the
> other, and DBIC would just DWIM, e.g.
>
> App::Schema1::RS->belongs_to( 'rec_from_schema2' => 'App::Schema2::RS',
> 'fk');
That's undwimmable - DBIC has no way of knowing what $schema object to use on
the other side, and a relationship in DBIC is expected to be a "proper" DB
relationship, i.e. one you can join on.
> Is there any way I can roll my own?
Use inflate_column - this is why where CDBI (which doesn't know what a JOIN
is) has has_a for both FKs and inflates, DBIC keeps belongs_to and
inflate_column separate.
Of course, if your databases were in the same DBMS you could potentially join
it properly - mysql people use ->table('dbname.tblname') just fine, similarly
with real databases and multiple schemas
More information about the Dbix-class
mailing list