I am a Catalyst/DBIx::Class beginner and have trouble with custom DBIx::Class SQL queries. My database table schema is the following:
CREATE TABLE `table1` ( `id` char(15) NOT NULL, `label` char(255) default NULL, `group` char(255) default NULL, PRIMARY KEY (`id`) )
I want to access to all distinct 'group' values within this table. So, in the Catalyst Controller, I try to do a custom DBIx::Class query:
sub test_distinct :Local { $c->stash->{distinct_groups} = [ $c->model('Database1')->resultset('Table1')->search( undef, { select => [ { distinct => 'group' }, ], order_by => 'group' }, ) ]; }
In the Template:
[% FOREACH item IN distinct_groups %] '[% item %]'<br /> [% END %]
The result I obtain is:
'TestApp::Schema::Database1::Table1=HASH(0x34a21a4)' 'TestApp::Schema::Database1::Table1=HASH(0x34a2234)' 'TestApp::Schema::Database1::Table1=HASH(0x34a7f00)'
In the table content, there are 3 distinct groups. The result seems to be consistent.
My problem is that I haven't yet found a way to access to the values of the groups. For instance, I have tried:
[% FOREACH item IN distinct_groups %] '[% item.group %]'<br /> [% END %]
... and I just obtain empty strings. What am I doing wrong ?

In reply to Catalyst, DBIx::Class, SELECT DISTINCT and TT by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.