in reply to Re: DBIx::Class::ResultSet disired hash output including related items
in thread DBIx::Class::ResultSet desired hash output including related items

I have tried something like the following,

my $artists = $schema->resultset('Artist') ; # $artists->result_class ('DBIx::Class::ResultClass::HashRefInflator'); # will cause errors my $artistAndTitles = $artists->next->cds() ; $artistAndTitles->result_class ('DBIx::Class::ResultClass::HashRefInflator'); while (my $hashref = $artistAndTitles->next) { print Dumper($hashref) ; }

But this way I only get a 'shallow' hash from the 'cds' result subset for only one row at a time instead of each Artist + all the titles.

Maybe there is another way? Examples appreciated.

  • Comment on Re^2: DBIx::Class::ResultSet disired hash output including related items
  • Download Code

Replies are listed 'Best First'.
Re^3: DBIx::Class::ResultSet disired hash output including related items
by spadacciniweb (Curate) on Feb 26, 2019 at 15:39 UTC
    Documentation report:

    ... Specifying this class as a result_class for a resultset will change $rs->next to return a plain data hash-ref (or a list of such hash-refs if $rs->all is used

    so last lines of your code turn in
    my @hashref = $artistAndTitles->all; print Dumper(\@hashref) ;

    ($_="nzz ojjdloobnf jjt tqqbebd77jojxfc")=~y~wb-zg2-5c96-8~aa-z0-9~s=~s~~~s;$_=~y~5-8~fuck~;print

      That still prints only one 'Artist' row at a time and it only prints data from 'cds' ('shallow'). I am looking for something much more sophisticated than that in the sense recursiveness and flexibility (e.g. being able to specify multiple relations either one-to-many or many-to-many on different levels and keeping the full functionality of the ResultSet class).

        It seems like you want basically the same thing TO_JSON does. There are a couple helpers for that on the CPAN often used in conjunction with a JSON View in web apps. I usually write them manually and it's maybe a step too far, from flattening to serializing when you just want them flattened… These are fun but a bit time consuming to put together so I can't try today. If no one steps in, I'll give it a shot when I can.