[Dbix-class] Help with many to many relationship
RAPPAZ Francois
francois.rappaz at unifr.ch
Wed Apr 2 05:53:34 GMT 2014
The Schema.pm and Schema folder are in a Dbc folder. The Schema.pm has package Dbc::Schema
The Result Folder in Schema folder holds the tables modules, for example Jrnabt.pm has package Dbc::Schema::Result::Jrnabt
When I fetch data from another table without using relationship, for example
my $s = Dbc::Schema->connect(
$dsn,
$cfg->get_usr,
$cfg->get_psw,
{
PrintError => 0,
RaiseError => 1,
AutoCommit => 1,
mysql_enable_utf8=>1
}
);
my $rs = $s->resultset('Ed')->search_rs( undef, {order_by => ['nom']} );
while (my $ed = $rs->next){
print $ed->nom , "\n";
}
It works
François
> -----Original Message-----
> From: Hailin Hu [mailto:i at h2l.name]
> Sent: mercredi, 2. avril 2014 04:14
> To: DBIx::Class user and developer list
> Subject: Re: [Dbix-class] Help with many to many relationship
>
> Show up the folder structure and the actual package names.
>
> On Wed, Apr 2, 2014 at 12:09 AM, RAPPAZ Francois
> <francois.rappaz at unifr.ch> wrote:
> > Hi
> >
> > I have two tables Abo (primary key: noabt) and Jrn (primary key:
> nofm)
> > join by a linking table jrnabt (primary keys: nofm, noabt)
> >
> > I have defined the relationship as
> >
> > Abo.pm
> > __PACKAGE__->has_many( abojrnabt => 'Dbc::Jrnabt', {'foreign.noabt'
> > => 'self.noabt'});
> >
> > Jrn.pm
> > __PACKAGE__->has_many(jrnjrnabt => 'Dbc::Jrnabt', {'foreign.nofm'
> =>
> > 'self.nofm'});
> >
> > Jrnabt.pm
> >
> > __PACKAGE__->belongs_to(jrnabtjrn => 'Dbc::Jrn', {'foreign.nofm' =>
> > 'self.nofm'}); __PACKAGE__->belongs_to(jrnabtabo => 'Dbc::Abo',
> > {'foreign.noabt' => 'self.noabt'});
> >
> > When I try
> > my $rs = $schema->resultset('Abo')->search_rs({'abojrnabt.nofm' =>
> > '1'}, {join => 'abojrnabt'});
> >
> > I got
> > DBIx::Class::Schema::source(): Can't find source for Dbc::Jrnabt at
> > U:\docs\perl\dokpe_i01_dbc\testdbc.pl line 62
> >
> > What am I missing ?
> >
> > Thanks
> >
> > François Rappaz
> >
> > Centre de documentation de la Faculté des Sciences Université de
> > Fribourg DokPe - Dokumentationszentrum der Naturwissenschaftlichen
> > Fakultät Universität Freiburg Pérolles CH-1700 Fribourg Switzerland
> > http://www.unifr.ch/dokpe/
> > Tel.: 41 (0)26 300 92 60
> > Fax.: 41 (0)26 300 97 30
> >
> >
> >
> > _______________________________________________
> > 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@lists.scsys.co.uk
>
> _______________________________________________
> 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 at lists.scsys.co.uk
More information about the DBIx-Class
mailing list