perl - DBIC- select specific columns in "prefetch" while maintaining has_many relationship -


i have 2 tables 'artist' has_many 'cd' .

i want fetch 'artist' , 'cds' , use hashrefinflator (json format) use 'hashrefinflator'.

     [ {          "artist_name": "dummy",         "artist_id": "1",             "cds": [{             "cd_id": "1,             "cd_desc": "dummy",             }],          },       ] 

1. when use
$schema->resultset('artist')->search({}, { prefetch => 'cds', }); result "extra" column cd table . want able select specific column 'cd'.

  1. when use

    $schema->resultset('artist')->search({}, {'+select' => [ 'columns need' ], '+as' => [ 'col names' ], });

    i 'columns need' merged main columns instead of hierarchy.

      [ {     "artist_name": "dummy",     "artist_id": "1",     "cds": []     **"cd_id": "1,     "cd_desc": "dummy",**        },     ] 

how can prefetch specific columns related table while maintaining hierarchical structure. ?

edit: sorry if not clear. problem here 'join' , '+columns' / '+select' not preserve hierarchical data structure. 'cds' should array of objects within 'artist' object.instead gets joined @ artist level. not use "collapse" have older version of dbix::class. try install later version , check.

use join instead of prefetch:

$schema->resultset('artist')->search(     {},     {         join         => ['cds'],         '+select'    => ['cd.desc'],         result_class => 'dbix::class::resultclass::hashrefinflator'     } ); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -