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

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

From: Dave Howorth
Subject: Re: [CDBI] Weirdness trying to limit Class::DBI has_many relationship from TT template
Date: 10:49 on 13 Oct 2005
William Ross wrote:
> On 13 Oct 2005, at 10:40, Will Hawes wrote:
>> 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.

That's the best way to write the call to that method, but it's not true 
to say that TT doesn't recognize =>. If you write:

   [% images = product.images(image_type => 1); %]

TT converts it into Perl something like this:

   $images = $product->images({ image_type => 1 })

Note the extra braces { }. And image_type is quoted automatically. (But 
it's not really manipulating variables called $images etc  - that's just 
for explanation :)

Perhaps more interesting:

   [% obj.meth( a => 1, b, c => 2, d ) %]

becomes

   $obj->meth(b, d, { a => 1, c => 2 });

If you're writing methods to be called from templates, it's best to plan 
to allow this calling style, otherwise people get frustrated when they 
write => in the template without thinking! So enhancing the images 
method might be the best thing to do.

Cheers, Dave


_______________________________________________
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
Dave Howorth 10:49 on 13 Oct 2005

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