many2many

[prev] [thread] [next] [Date index for 2005/04/11]

From: Barry Dancis
Subject: many2many
Date: 16:46 on 11 Apr 2005
This is a multi-part message in MIME format.

------=_NextPart_000_00E2_01C53E94.89E93090
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am trying to implement a many to many relationship with

#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
{package Sites;
  Sites->has_many (siteenzymes  =3D> ['EnzymeSites' =3D> 'enzid']);

#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
{package Enzymes;
  Enzymes->has_many (enzsites =3D> ['EnzymeSites' =3D> 'siteid']);

#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
{package EnzymeSites;
  EnzymeSites->columns(Primary =3D> qw/ siteid enzid /);
  EnzymeSites->has_a (enzid  =3D> 'Enzymes');
  EnzymeSites->has_a (siteid  =3D> 'Sites');

but when I execute:

  my $enzyme =3D Enzymes->retrieve(enzyme =3D> 'TstI');
  my @sites =3D $enzyme->enzsites;

I get the error:

    enzymes is not a column of EnzymeSites

If I add

  __PACKAGE__->has_many(allsites =3D> 'EnzymeSites', 'enzid');
 sub actors {=20
     my $self =3D shift;
     return map $_->siteid->site, $self->allsites;=20
 }

to  the Enzymes package and execute

  my @sites =3D $enzyme->actors;
  print "$enzyme sites\n" . join ("\n", @sites), "";

=20
it works fine.

What is causing the error?

Thanks,

Barry

------=_NextPart_000_00E2_01C53E94.89E93090
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2604" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am trying to implement a many to many =

relationship with</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>{package Sites;<BR>&nbsp;=20
Sites-&gt;has_many (siteenzymes&nbsp; =3D&gt; ['EnzymeSites' =3D&gt; =
'enzid']);<BR>
<DIV><FONT face=3D"Courier New"=20
size=3D2>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D</FONT></DIV>{package Enzymes;<BR>&nbsp;=20
Enzymes-&gt;has_many (enzsites =3D&gt; ['EnzymeSites' =3D&gt; =
'siteid']);<BR>
<DIV><FONT face=3D"Courier New"=20
size=3D2>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D</FONT></DIV>{package=20
EnzymeSites;<BR>&nbsp; EnzymeSites-&gt;columns(Primary =3D&gt; qw/ =
siteid enzid=20
/);<BR>&nbsp; EnzymeSites-&gt;has_a (enzid&nbsp; =3D&gt; =
'Enzymes');<BR>&nbsp;=20
EnzymeSites-&gt;has_a (siteid&nbsp; =3D&gt; 'Sites');</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>but when I execute:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; my $enzyme =3D=20
Enzymes-&gt;retrieve(enzyme =3D&gt; 'TstI');<BR>&nbsp;&nbsp;my @sites =
=3D=20
$enzyme-&gt;enzsites;<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I get the error:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; enzymes is =
not a column=20
of EnzymeSites</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If I add</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; =
__PACKAGE__-&gt;has_many(allsites=20
=3D&gt; 'EnzymeSites', 'enzid');<BR>&nbsp;sub actors=20
{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; my $self =3D shift;<BR>&nbsp; =
&nbsp;&nbsp;=20
return map $_-&gt;siteid-&gt;site,=20
$self-&gt;allsites;&nbsp;<BR>&nbsp;}<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>to&nbsp; the Enzymes package and=20
execute</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Courier New">&nbsp; my =
@sites =3D=20
$enzyme-&gt;actors;<BR>&nbsp; print "$enzyme sites\n" . join ("\n", =
@sites),=20
"";<BR></FONT></DIV></FONT>
<DIV><FONT face=3DArial size=3D2> <BR>it works fine.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></DIV>
<DIV><FONT face=3DArial size=3D2>What is causing the error?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Barry</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_00E2_01C53E94.89E93090--


many2many
Barry Dancis 16:46 on 11 Apr 2005

Re: many2many
William Ross 18:58 on 11 Apr 2005

Re: many2many
Tony Bowden 19:17 on 11 Apr 2005

Re: many2many
William Ross 19:38 on 11 Apr 2005

Re: many2many
Barry Dancis 14:43 on 12 Apr 2005

Re: many2many
William Ross 17:23 on 12 Apr 2005

Re: many2many
Barry Dancis 15:43 on 12 Apr 2005

Generated at 12:49 on 16 Apr 2005 by mariachi v0.52