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

Michael South msouth at mcclatchyinteractive.com
Mon Oct 17 15:20:25 BST 2005


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 at template-toolkit.org
> 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 at mcclatchyinteractive.com
AIM : msouthmi





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/mailman/private/classdbi/attachments/20051017/c5e7cd70/attachment.htm


More information about the ClassDBI mailing list