I have two tables with 'Artist' has_many
'CD' .
I want to fetch 'artist' and 'CDs' and use HashRefInflator to get something like (JSON format) I use 'HashRefInflator'.
[ {
"artist_name": "Dummy",
"artist_id": "1",
"cds": [{
"cd_id": "1,
"cd_desc": "Dummy",
}],
},
]
When I use
$schema->resultset('Artist')->search({},
{
prefetch => 'cds',
});
I get result with "EXTRA" column from CD table. I want to be able to select only specific column from 'CD'.
When I use
$schema->resultset('Artist')->search({},
{'+select' => [ 'columns I need' ],
'+as' => [ 'col names' ],
});
I get 'columns i need' merged with main columns instead of a hierarchy.
[ {
"artist_name": "Dummy",
"artist_id": "1",
"cds": []
**"cd_id": "1,
"cd_desc": "Dummy",**
},
]
How can I prefetch specific columns from related table while maintaining the hierarchical structure?
Edit: I am sorry if I was not very clear. The problem here with join
and +columns
/ +select
is that it does not preserve the hierarchical data structure.
The 'cds' should be an array of objects within 'Artist' object.Instead it gets joined at Artist level. I could not use "collapse" as I have an older version of DBIx::Class. I would try to install a later version and check.