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

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

From: Will Hawes
Subject: Re: [CDBI] Weirdness trying to limit Class::DBI has_many relationship from TT template
Date: 10:49 on 13 Oct 2005
Thanks, that works, but I'm still a bit confused about the passing of ha=
shrefs to object methods from within TT. This does not work:

[% images =3D product.images( { 'image=5Ftype' =3D> 1 } ); %]

Given the comments in the docs at http://www.template-toolkit.org/docs/p=
lain/Manual/Variables.html#Hash=5FArray=5FReferences under "You can use =
Perl's familiar..." however, I would have expected the following to work=
 (and it doesn't):

[%
criteria =3D {
  'image=5Ftype' =3D> 1
};
images =3D product.images( criteria );
%]

Is the problem here simply that TT doesn't allow you to pass a hashref t=
o an object method=3F

----- Original Message -----
From: William Ross <will@xxxxxxx.xxx>
To: Will Hawes <info@xxxxxx.xx.xx>
Cc: Class DBI <classdbi@xxxxx.xxxxxxxxxxxxxxxx.xxx>
Sent: Thu, 13 Oct 2005 11:10:50 +0100
Subject: Re: [CDBI] Weirdness trying to limit Class::DBI has=5Fmany rela=
tionship from TT template


>=20
> On 13 Oct 2005, at 10:40, Will Hawes wrote:
>=20
> > I'm attempting to limit the results returned via a has=5Fmany =20
> > relationship using Class::DBI 0.96 and Template Toolkit 2.14.
> >
> > in My/Product.pm:
> > =5F=5FPACKAGE=5F=5F->has=5Fmany(images =3D> ['My::ProductImage' =3D>=
 'image']);
> >
> > in My/ProductImage.pm:
> > =5F=5FPACKAGE=5F=5F->has=5Fa('image' =3D> 'My::Image');
> >
> > This code works fine - only My::Images with image=5Ftype =3D=3D 1 ar=
e =20
> > returned:
> >
> >  my $product =3D My::Product->retrieve(1);
> >  my @images =3D $product->images(image=5Ftype =3D> 1)
> >
> > Trying to do the same from a template doesn't work.
> >
> > [% images =3D product.images(image=5Ftype =3D> 1); %]
> >
> > I have tried several variations of the above in my template (e.g. =
=20
> > replacing "=3D>" with "=3D", trying with and without "{}"), but to n=
o =20
> > avail. In every case, all My::Image objects get returned and the =20
> > limit criteria are ignored. I don't understand why.
>=20
> the =3D> is a comma that happens to also quote its left hand argument.=
 =20
> TT doesn't recognise it, so you need to spell it out:
>=20
> [% images =3D product.images('image=5Ftype', 1) %]
>=20
> should work.
>=20
> will
>=20
>=20


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

Re: [CDBI] Weirdness trying to limit Class::DBI has_many relationship from TT template
Will Hawes 10:49 on 13 Oct 2005

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