[Catalyst] Debugging help needed

J. Shirley jshirley at gmail.com
Sun Mar 29 16:15:18 BST 2009


On Sun, Mar 29, 2009 at 4:52 AM, Jesse Sheidlower <jester at panix.com> wrote:

>
> I'm having a problem with an app that is totally mystifying
> me, and several attempts to put it aside and look at it the
> next day have failed to help me solve it. I'm sure it's
> something totally obvious, but nothing springs to mind, so I'd
> welcome any suggestions.
>
> I have a project where in one place I hard-coded some values
> for a select list, going into a database row; now I'm moving
> these into a table, and storing the id to this in the original
> table. I have done similar things in other projects
> before. This project is flexible, using a base controller and
> so forth, so I figured all I needed to do was create a new
> class or two and some templates, and all would work. Yet it's
> failing, even though exactly parallel examples in the same app
> are working fine.
>
> The basic problem is that when I retrieve my records, things
> look like they're working--DBIC_TRACE shows that my query is
> being fired; the pager that's associated with the resultset
> shows the correct values; etc. But the actual looping over
> the results doesn't show anything.
>
> In my base controller, the relevant part is this:
>
>  $c->stash->{record} =3D $c->stash->{model}->search(undef,
> $search_conditions);
>  $c->stash->{pager} =3D $c->stash->{record}->pager;
>
> ($search_conditions is a hashref for the page and row
> information for the pager; the model stuff is previously set
> in an earlier part of the chain).
>
> Then, in my TT template, I have (the comments with "####" are
> things added for this post, they're not in the original):
>
> ---
> [% SET tunings =3D record %]  #### dumping "tunings" here shows it's a DB=
IC
> object
>
> <p><span class=3D"lead">
>    [% IF pager.total_entries =3D=3D 1  %]
>        1 record
>    [% ELSE %]
>        [% pager.total_entries %] records
>    [% END %]
> found; displaying [% pager.first %] &ndash; [% pager.last %]</span></p>
>
> #### this displays "7 records found; displaying 1 - 7", so
> #### clearly the pager has been correctly set up, and it comes from
> #### "record". Furthermore, if I replace "pager" with "record.pager"
> #### things still work, so "record" seems to have the correct thing
> #### even in the template
>
> <table>
>
> [% rowcolor =3D "lightrow" %]
>
> [% WHILE (tuning =3D tunings.next) %]
>
> #### I have the same thing in another virtually identical
> #### template; it works there. Also, replacing "tunings" with
> #### "record" fails in the same way, and changing "tuning"
> #### to "fqqx" or something else also fails
>
>  <tr class=3D"[% rowcolor %]">
>    <td><a href=3D"[% base _ 'tuning/view/' _ tuning.id %]">[% tuning
> %]</a></td>
>  </tr>
>
> [% SET rowcolor =3D (rowcolor =3D=3D "lightrow" ? "darkrow" : "lightrow")=
 %]
> [% END # while %]
>
> </table>
>
> #### the result is empty <table>    </table>
> ---
>
> Similarly, in the other place where I use this, where I'm
> generating the select list, it fails in the same way. In
> that controller I have:
>
>  $c->stash->{performers} =3D $c->model('GuitarDB::Performer')->search();
>  $c->stash->{tunings} =3D $c->model('GuitarDB::Tuning')->search();
>
> And in the template (with some display stuff not shown):
>
>  <select name=3D"performer_id" id=3D"performer">
>    <option value=3D"" selected=3D"selected">(No performer)</option>
>    [% WHILE ( performer =3D performers.next ) %]
>       <option value=3D"[% performer.id %]">[% performer %]</option>
>    [% END %]
>  </select>
>
>  <select name=3D"tuning_id" id=3D"tuning">
>    <option value=3D"">(No tuning)</option>
>    [% WHILE ( tuning =3D tunings.next ) %]
>        <option value=3D"[% tuning.id %]">[% tuning %]</option>
>    [% END %]
>  </select>
>
> The first one works, the second doesn't. DBIC_TRACE shows that
> both queries (performer and tuning) are being fired, and
> executing them each manually against the database shows that
> the expected results are being returned.
>
> Can someone kick me, and tell me the obvious typo, or use of a
> reserved word, or whatever, that I'm missing?
>
> Thanks.
>
> Jesse Sheidlower
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>


Do you have a string overload on [% tuning %] (that perhaps is returning an
empty string)?
If you do [% tunings %] does it return the scalar count?  TT can be
maddening when it does "helpful" things to your values in various contexts
(array folding, etc).

Is the [% tuning.id %] rendering ok, or not at all?  Are you getting the
same amount of <option> lines that you expect, just empty?

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090329/762e8=
605/attachment.htm


More information about the Catalyst mailing list