Creating a relationship

3 messages Options
Embed this post
Permalink
Sungsam Gong

Creating a relationship

Reply Threaded More More options
Print post
Permalink
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

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Sungsam Gong

Fwd: Creating a relationship

Reply Threaded More More options
Print post
Permalink
My email below does not seem to be sent properly.
Am trying again...


---------- Forwarded message ----------
From: Sungsam Gong <[hidden email]>
Date: 2009/9/16
Subject: Creating a relationship
To: "DBIx::Class user and developer list" <[hidden email]>


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

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Nigel Metheringham

Re: Fwd: Creating a relationship

Reply Threaded More More options
Print post
Permalink

On 16 Sep 2009, at 20:43, Sungsam Gong wrote:

> My email below does not seem to be sent properly.

Please don't do that.  You are using gmail - its quite normal for  
gmail to hide your own postings to a mailing list from you.

        Nigel.

--
[ Nigel Metheringham             [hidden email] ]
[ - Comments in this message are my own and not ITO opinion/policy - ]


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...