----- Original Message -----
From: Sergey Martynoff <[EMAIL PROTECTED]>
To: 'Will Hawes' <[EMAIL PROTECTED]>
Cc: [email protected]
Sent: Thu, 13 Oct 2005 12:25:07 +0100
Subject: RE: [Templates] Re: [CDBI] Weirdness trying to limit Class::DBI 
has_many relationship from TT template


> 
> > 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:
> 
> 
> > [%
> > criteria = {
> >   'image_type' => 1
> > };
> > images = product.images( criteria );
> > %]
> 
> If 'images' method really expects hashref - this should work ok.
> Try to insert parameters dumping into this method.
> 
> 
> > Is the problem here simply that TT doesn't allow you to pass 
> > a hashref to an object method?
> 
> TT _does_ allow to pass hashref, and even more - it _will_ pass a
> hashref when you write code like this (note, that there is no
> curly brackets!):
> 
> [% images = product.images( 'image_type' => 1 ); %]
> 
> This is a bit confusing, because there is still modules, which
> accept parameters as hash, not hasref. Example:
> 
> sub method {
>       my %params = @_;
>       # do something with $params{param_key}
> }
> 
> In this case you have to write:
> 
> [% some.method( 'param_key', 'param_value' ); # passes an array of
> params %]
> 
> Instead of convenient:
> 
> [% some.method( param_key => 'param_value' ); # this passes a
> hasref and thus DOES NOT WORK %]
> 
> 
> -- 
> Sergey Martynoff

I think that's hit the nail on the head. In 
Class::DBI::Relationship::HasMany::_hm_run_search(), which does the search for 
the related class, assumes that the search arguments are passed as a list. 
Unlike the main search() method for a CDBI class, it doesn't allow a hashref 
instead.


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to