[Dbix-class] Related results, prefetch, paging = problem
Mark Blythe
list at markblythe.com
Tue Nov 27 16:01:29 GMT 2007
I ran into this just the other day, too. It has specifically to do
with the nested relationship + fetching a subsest of columns. You can
do it, but you have to use a "join" instead of a "prefetch" and then
clarify things a bit further with an "as". Try this:
$c->stash->{routes} = $c->model('QDB::Routes')->search(
{
'me.net_id' => $c->stash->{net_id},
'me.route_beg' => $c->stash->{node_id_beg},
'me.route_end' => $c->stash->{node_id_end},
},
{
join => { 'xc_params' => 'nodes' },
columns => [qw/
me.route_id me.route_beg me.route_end
me.err_code me.comment me.net_id
xc_params.node_rank xc_params.ch_beg xc_params.ch_end
nodes.node_id nodes.node_name
/ ],
as => [qw/
route_id route_beg route_end err_code comment net_id
xc_params.node_rank xc_params.ch_beg xc_params.ch_end
xc_params.nodes.node_id xc_params.nodes.node_name
/ ],
#TODO Paged output
order_by => [ @order_by ],
page => $page, # page to return
(defaults to 1)
rows => $rows, # number of results per page,
cache => 1
}
);
Note that you have to reflect the nested relationship in the naming of
the "as" attribute.
Try that and see if it works for you.
More information about the DBIx-Class
mailing list