[Dbix-class] Related results, prefetch, paging = problem

dreel dreel at bk.ru
Tue Nov 27 14:38:39 GMT 2007


Today I was trying to make a resultset with specifed set of columns and prefetch. And it's all will be paged trough pager.  
But it simply fails. IMHO it's relations problem - I think relation requests full set of columns and if I don't put them all in select it breaks. 

Code:

$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},
		},
		{
			prefetch => { '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
			/ ],

			#TODO Paged output
			order_by => [ @order_by ],
			page     => $page,       # page to return (defaults to 1)
			rows     => $rows,       # number of results per page,
			cache => 1
		}
	);
This code throw 
[error] Couldn't render template "undef error - DBIx::Class::ResultSet::all(): No such relationship 'nodes'

If I don't use columns it's prefetch all columns from me.* xc_params.*  nodes.* but this tables has the identical named columns (PK, FK) and pager crashes on it/

SQL reports some column used more then on time. 
CODE:

SELECT * FROM
(
    SELECT TOP 50 * FROM
    (
       SELECT TOP 50  me.route_id, xc_params.route_id, xc_params.node_id, nodes.node_id, nodes.node_name
       FROM vi_route me LEFT JOIN vi_xcparams xc_params 
       ON ( xc_params.route_id = me.route_id ) 
       LEFT JOIN vi_nodes nodes 
       ON ( nodes.node_id = xc_params.node_id ) 
                                                 ORDER BY me.route_id
    ) AS foo
    ORDER BY me.route_id DESC
) AS bar
ORDER BY me.route_id

It there any way to use prefetch with limitted set of columns?

---
dr.eel



More information about the DBIx-Class mailing list