DBIx::Class has a mis-feature where the ->search method is context-aware. In list context, it runs the query and you get back the rows. In scalar context it returns a resultset which you can continue chaining methods on and decide to run the query later. One workaround is the ->search_rs method which always returns a resultset.

The ->all method always returns a list (not arrayref) of rows. You got "123" because you tried assigning a list to a scalar, which gives you the size of the list.

The rows are objects by default. If you want hashrefs, use DBIx::Class::ResultClass::HashRefInflator. You can also use $row->get_columns to dump the key/value pairs from a row object but if you don't want the object in the first place, just use HashRefInflator and get better performance.

If you are doing a lot of work with DBIx::Class, consider using DBIx::Class::Helper::ResultSet which smooths over some of the rough edges of the DBIx::Class API. With this module installed, you can write:

for my $hashref ($c->model('DB::Thing')->hri->all) { ... }

In reply to Re: Issues with DBIx::Class by NERDVANA
in thread Issues with DBIx::Class by LittleJack

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.