[Dbix-class] establishing relationship across databases
Sungsam Gong
gong.sungsam at gmail.com
Thu Sep 20 10:18:41 GMT 2012
Hi,
I have been creating a manual relationship between tables (mysql
MyISAM) within the same database, which worked very well for my
purpose.
Just wondering whether it's possible to make a relationship between
two tables each of which residues in different database.
For example,
package Nectar::Schema::UNIPROT::Result::SwissVariant;
...
__PACKAGE__->has_many('2UniProts',
'Nectar::Schema::CARDIODB::Result::2UniProt',
{'foreign.uniprot'=>'self.sp_acc',
'foreign.res_num'=>'self.res_num'});
Then, within the controller:
$c->stash->{humsavars}=[$c->model("UNIPROT::SwissVariant")->search(
{gene=>$hgnc},
{
join=>[qw/2UniProts/],
'+select'=>[qw/2UniProts.uid/],
'+as'=>[qw/uid/],
distinct=>1,
}
)];
I tried this, but with no luck.
It complains:
Can't find source for Nectar::Schema::CARDIODB::Result::2UniProt at
/home/sung/perl5/lib/perl5/DBIx/Class/Schema.pm line 1088
DBIx::Class::Schema::throw_exception('Nectar::Schema::UNIPROT=HASH(0x1fa53990)',
'Can\'t find source for Nectar::Schema::CARDIODB::Result::2Uni...')
called at /home/sung/perl5/lib/perl5/DBIx/Class/Schema.pm line 601
DBIx::Class::Schema::source('Nectar::Schema::UNIPROT=HASH(0x1fa53990)',
'Nectar::Schema::CARDIODB::Result::2UniProt') called at
/home/sung/perl5/lib/perl5/DBIx/Class/ResultSource.pm line 1853
DBIx::Class::ResultSource::related_source('DBIx::Class::ResultSource::Table=HASH(0x1f9fc490)',
'2UniProts') called at
/home/sung/perl5/lib/perl5/DBIx/Class/ResultSource.pm line 1511
DBIx::Class::ResultSource::_resolve_join('DBIx::Class::ResultSource::Table=HASH(0x1f9fc490)',
'2UniProts', 'me', 'HASH(0x21388770)', 'ARRAY(0x22151f30)', 'undef')
called at /home/sung/perl5/lib/perl5/DBIx/Class/ResultSource.pm line
1469
DBIx::Class::ResultSource::_resolve_join('DBIx::Class::ResultSource::Table=HASH(0x1f9fc490)',
'ARRAY(0x22142e90)', 'me', 'HASH(0x21388770)', 'ARRAY(0x20799980)')
called at /home/sung/perl5/lib/perl5/DBIx/Class/ResultSet.pm line 3251
...
If cross-database joining is not possible, any workaround for this?
Cheers,
Sung
More information about the DBIx-Class
mailing list