Thanks, that works, but I'm still a bit confused about the passing of hashrefs
to object methods from within TT. This does not work:
[% images = product.images( { 'image_type' => 1 } ); %]
Given the comments in the docs at
http://www.template-toolkit.org/docs/plain/Manual/Variables.html#Hash_Array_References
under "You can use Perl's familiar..." however, I would have expected the
following to work (and it doesn't):
[%
criteria = {
'image_type' => 1
};
images = product.images( criteria );
%]
Is the problem here simply that TT doesn't allow you to pass a hashref to an
object method?
----- Original Message -----
From: William Ross <[EMAIL PROTECTED]>
To: Will Hawes <[EMAIL PROTECTED]>
Cc: Class DBI <[EMAIL PROTECTED]>
Sent: Thu, 13 Oct 2005 11:10:50 +0100
Subject: Re: [CDBI] Weirdness trying to limit Class::DBI has_many relationship
from TT template
>
> On 13 Oct 2005, at 10:40, 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.
>
> the => is a comma that happens to also quote its left hand argument.
> TT doesn't recognise it, so you need to spell it out:
>
> [% images = product.images('image_type', 1) %]
>
> should work.
>
> will
>
>
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates