[CDBI] Re: [Templates] Weirdness trying to limit Class::DBI has_many relationship from TT template

[prev] [thread] [next] [Date index for 2005/10/17]

From: Michael South
Subject: [CDBI] Re: [Templates] Weirdness trying to limit Class::DBI has_many relationship from TT template
Date: 14:20 on 17 Oct 2005
--===============1636868256==
Content-Type: multipart/alternative; boundary=Apple-Mail-1-927770157


--Apple-Mail-1-927770157
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed


On Oct 13, 2005, at 5:40 AM, Will Hawes wrote:

> I'm attempting to limit the results returned via a has_many  
> relationship using Class::DBI 0.96 and Template Toolkit 2.14.
>
> in My/Product.pm:
> __PACKAGE__->has_many(images => ['My::ProductImage' => 'image']);
>
> in My/ProductImage.pm:
> __PACKAGE__->has_a('image' => 'My::Image');
>
> This code works fine - only My::Images with image_type == 1 are  
> returned:
>
>  my $product = My::Product->retrieve(1);
>  my @images = $product->images(image_type => 1)
>
> Trying to do the same from a template doesn't work.
>
> [% images = product.images(image_type => 1); %]
>
> I have tried several variations of the above in my template (e.g.  
> replacing "=>" with "=", trying with and without "{}"), but to no  
> avail. In every case, all My::Image objects get returned and the  
> limit criteria are ignored. I don't understand why.
Try just a comma.  Using '=>' triggers Toolkit's behavior where it  
bundles all named arguments into a hashref and puts it at the end of  
the argument list.   It's been a while since I worked on this, but if  
I remember correctly you should be able to get around that by using a  
plain comma.

mike


>
> _______________________________________________
> templates mailing list
> templates@xxxxxxxxxxxxxxxx.xxx
> http://lists.template-toolkit.org/mailman/listinfo/templates
>

--
Name : Mike South
Title : Software Developer
Company : McClatchy Interactive
Phone : (919) 861-1259
Cell : (919) 624-5071
Fax : (919) 861-1300
Email : msouth@xxxxxxxxxxxxxxxxxxxx.xxx
AIM : msouthmi






--Apple-Mail-1-927770157
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=ISO-8859-1

<HTML><BODY style=3D"word-wrap: break-word; -khtml-nbsp-mode: space; =
-khtml-line-break: after-white-space; "><BR><DIV><DIV>On Oct 13, 2005, =
at 5:40 AM, Will Hawes wrote:</DIV><BR =
class=3D"Apple-interchange-newline"><BLOCKQUOTE type=3D"cite">  =
<P><TT><FONT size=3D"2">I'm attempting to limit the results returned via =
a has_many relationship using Class::DBI 0.96 and Template Toolkit =
2.14.</FONT></TT></P><P><TT><FONT size=3D"2">in =
My/Product.pm:</FONT></TT> <BR><TT><FONT =
size=3D"2">__PACKAGE__-&gt;has_many(images =3D&gt; ['My::ProductImage' =
=3D&gt; 'image']);</FONT></TT> </P><P><TT><FONT size=3D"2">in =
My/ProductImage.pm:</FONT></TT> <BR><TT><FONT =
size=3D"2">__PACKAGE__-&gt;has_a('image' =3D&gt; =
'My::Image');</FONT></TT> </P><P><TT><FONT size=3D"2">This code works =
fine - only My::Images with image_type =3D=3D 1 are =
returned:</FONT></TT> </P><P><TT><FONT size=3D"2">=A0my $product =3D =
My::Product-&gt;retrieve(1);</FONT></TT> <BR><TT><FONT size=3D"2">=A0my =
@images =3D $product-&gt;images(image_type =3D&gt; 1)</FONT></TT> =
</P><P><TT><FONT size=3D"2">Trying to do the same from a template =
doesn't work.</FONT></TT> </P><P><TT><FONT size=3D"2">[% images =3D =
product.images(image_type =3D&gt; 1); %]</FONT></TT> </P><P><TT><FONT =
size=3D"2">I have tried several variations of the above in my template =
(e.g. replacing "=3D&gt;" with "=3D", trying with and without "{}"), but =
to no avail. In every case, all My::Image objects get returned and the =
limit criteria are ignored. I don't understand =
why.</FONT></TT></P></BLOCKQUOTE>Try just a comma.=A0 Using '=3D&gt;' =
triggers Toolkit's behavior where it bundles all named arguments into a =
hashref and puts it at the end of the argument list.=A0 =A0It's been a =
while since I worked on this, but if I remember correctly you should be =
able to get around that by using a plain comma.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>mike</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV><BR><BLOCKQUOTE =
type=3D"cite"> <BR><P><TT><FONT =
size=3D"2">_______________________________________________</FONT></TT> =
<BR><TT><FONT size=3D"2">templates mailing list</FONT></TT> =
<BR><TT><FONT size=3D"2"><A =
href=3D"mailto:templates@xxxxxxxxxxxxxxxx.xxx">templates@template-toolkit.=
org</A></FONT></TT> <BR><TT><FONT size=3D"2"><A =
href=3D"http://lists.template-toolkit.org/mailman/listinfo/templates">http=
://lists.template-toolkit.org/mailman/listinfo/templates</A></FONT></TT> =
</P>  </BLOCKQUOTE></DIV><BR><DIV> <SPAN class=3D"Apple-style-span" =
style=3D"border-collapse: separate; border-spacing: 0px 0px; color: =
rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: =
normal; font-variant: normal; font-weight: normal; letter-spacing: =
normal; line-height: normal; text-align: auto; =
-khtml-text-decorations-in-effect: none; text-indent: 0px; =
-apple-text-size-adjust: auto; text-transform: none; orphans: 2; =
white-space: normal; widows: 2; word-spacing: 0px; "><SPAN =
class=3D"Apple-style-span" style=3D"border-collapse: separate; =
border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; =
font-size: 12px; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; text-align: auto; =
-khtml-text-decorations-in-effect: none; text-indent: 0px; =
-apple-text-size-adjust: auto; text-transform: none; orphans: 2; =
white-space: normal; widows: 2; word-spacing: 0px; "><SPAN =
class=3D"Apple-style-span" style=3D"border-collapse: separate; =
border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; =
font-size: 12px; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; text-align: auto; =
-khtml-text-decorations-in-effect: none; text-indent: 0px; =
-apple-text-size-adjust: auto; text-transform: none; orphans: 2; =
white-space: normal; widows: 2; word-spacing: 0px; "><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">--</DIV><DIV style=3D"margin-top: 0px; margin-right: =
0px; margin-bottom: 0px; margin-left: 0px; ">Name : Mike South</DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">Title : Software Developer</DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">Company : McClatchy Interactive</DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">Phone : (919) 861-1259</DIV><DIV style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Cell : =
(919) 624-5071</DIV><DIV style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; ">Fax : (919) 861-1300</DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">Email : <A =
href=3D"mailto:msouth@xxxxxxxxxxxxxxxxxxxx.xxx">msouth@mcclatchyinteractiv=
e.com</A></DIV><DIV style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; ">AIM : msouthmi</DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; "><BR class=3D"khtml-block-placeholder"></DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><BR =
class=3D"Apple-interchange-newline"></SPAN></SPAN></SPAN> =
</DIV><BR></BODY></HTML>=

--Apple-Mail-1-927770157--


--===============1636868256==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

--===============1636868256==--

[CDBI] Re: [Templates] Weirdness trying to limit Class::DBI has_many relationship from TT template
Michael South 14:20 on 17 Oct 2005

Generated at 15:35 on 18 Oct 2005 by mariachi v0.52