[Dbix-class] Creating a relationship
Sungsam Gong
gong.sungsam at gmail.com
Wed Sep 16 11:36:01 GMT 2009
Hi,
I'm using DBIx::Class::Schema::Loader for a schema generation from a
mysql backend.
package DB::UNIPROT;
use strict;
use warnings;
use base qw/DBIx::Class::Schema::Loader/;
__PACKAGE__->loader_options(
debug => $ENV{DBIC_TRACE} || 0,
);
1;
A relationship was normally defined in another main perl script as
shown in the cookbook
(http://search.cpan.org/~ribasushi/DBIx-Class-0.08111/lib/DBIx/Class/Manual/Cookbook.pod#JOINS_AND_PREFETCHING).
For example, in the main script;
DB::UNIPROT::Featureclass->belongs_to(rel_name,
'DB::UNIPROT::Featureclass', {'foreign.id'=>'self.featureClass'});
'join' runs smoothly with no problems and everything was fine until I
recently updated DBIx::Class (0.081) of my local linux (2.6.18) box.
my $rs=$schema->resultset('Feature')->search_rs(
{'featureClass.val'=>'ACT_SITE'},
{
join=>'rel_name',
}
)->slice(0,5);
However, after updating DBIx, I got an error message as shown below;
No such relationship relname at
/usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 1027
DBIx::Class::Schema::throw_exception('DB::UNIPROT=HASH(0xbadbb90)',
'No such relationship relname') called at
/usr/lib/perl5/site_perl/5.8.8/DBIx/Class/ResultSource.pm line 1578
blablabla.....
I solved the problem by dumping database schema into a file using
'make_schema_at' and 'dump_to_dir' functions and then edited the
schema file by inserting a line which defines a relation;
__PACKAGE__->belongs_to(rel_name, 'DB::UNIPROT::Featureclass',
{'foreign.id'=>'self.featureClass'});
Of course, I deleted the relationship definition in the main script.
Then, it worked!
But, I'm not happy as I have to modify my applications which had no
problems with the previous version of DBIx.
The only difference is where I defined the relations (plus schema dumping) .
Can anybody please advise me what has changed in the newer version?
Or did I just miss something?
Cheers,
Sung
More information about the DBIx-Class
mailing list