[dancer-users] dancer1 and DBIx: can I modify the returned result in a view?

John Stoffel john at stoffel.org
Wed Jul 21 14:25:10 EDT 2021


>>>>> "John" == John Stoffel <john at stoffel.org> writes:

John> I'm tasked with hacking an old Dancer1 app I wrote back in 2014/2015
John> which basically just returns from results from a DB query.  One of the
John> fields is called 'url' and I need to tweak it, since the URL in the DB
John> is completely wrong.

John> I've tried poking at it in my views/search.tt file, but I can't figure
John> out the right syntax to make it work.  My results loop looks like
John> this:

John>   <% IF results.size %>
John>       Results (found <% results.size %> matches):
John>       <ul>
John>         <% FOREACH result IN results %>
John>          <li><% result.full_name.replace("((?i)$tobold)",'<b>$1</b>') %>
John>             <ul>
John> 	       <% FOREACH a IN result.account %>
John> 	         <li><a href="<% a.url() %>" target="_blank">
John>                    Account # <% a.account_number  %>,
John>                    <% IF a.volume() %> Volume: <% a.volume() %>, <% END %>
John>                    <% IF a.box() %> Box: <% a.box() %>, <% END %>
John>                    <% IF a.folder() %> Folder: <% a.folder() %>, <% END %>
John>                   <% IF a.range() %> Range: <% a.range() %> <% END %>
John> 		  </a> <% newurl %><br>
John> 	      <% END %>
John> 	  </ul>
John>        <% END %>

And it turns out it's really something to be better handled in the
DBIx side of the house, and I've managed to fix it using an accessor
override (see the DBIx FAQ and Goodies pages) which will probably
break future use of dbicdump, but since this is a simple readonly
site, I don't care.

So basically, in the lib/Carey/Schema/Result/Account.pm file I had to
add some quick bits of code and all is well now.

Cheers,
John


More information about the dancer-users mailing list