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

If I have undestand, you have to use ResultClass::HashRefInflator
An example in documentation page.

($_="nzz ojjdloobnf jjt tqqbebd77jojxfc")=~y~wb-zg2-5c96-8~aa-z0-9~s=~s~~~s;$_=~y~5-8~fuck~;print
  • Comment on Re: DBIx::Class::ResultSet disired hash output including related items

Replies are listed 'Best First'.
Re^2: DBIx::Class::ResultSet disired hash output including related items
by Veltro (Hermit) on Feb 26, 2019 at 14:54 UTC

    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.

      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).