[Dbix-class] Custom ResultSource and 'in'
Chris Burch
cburch at madison.k12.wi.us
Mon Mar 30 18:49:03 BST 2009
Hello,
I'm wondering if it is possible to use SQL in a custom ResultSource as shown in the cookbook, and then binding an array parameter to an 'in' condition. This is against a SQL Server 2005 db.
>From my Tasks class, copied straight from the cookbook:
####
# Make a new ResultSource based on the Tasks class
my $source = __PACKAGE__->result_source_instance();
my $new_source = $source->new($source);
$new_source->source_name('CommonTasks');
# Hand in your query as a scalar reference
# It will be added as a sub-select after FROM,
# so pay attention to the surrounding brackets!
$new_source->name( \<<SQL );
( select t.sectionid,t.termid,t.taskid,t.taskname
from webapps.vOpenGradingTasks t
where t.sectionid in (?)
and t.termid = ?
group by t.sectionid,t.termid,t.taskid,t.taskname
having count(t.sectionid) = ? )
SQL
# Finally, register your new ResultSource with your Schema
ScoreCommenter::Warehouse->register_source('CommonTasks' => $new_source);
####
Then, in my Catalyst controller, I have:
####
my $task_rs = $c->model('Warehouse')->resultset('CommonTasks')->search( {},
{
bind => [ @section_list, $termid, $section_ct ]
}
);
####
Obviously this doesn't work, because I'm sending 4 parameters and the resultsource is only expecting 3.
Is there a way to get my array into that 'in(?)'?
Thanks in advance,
Chris
Chris Burch
Data Analyst/Web Programmer
Planning/Research & Evaluation
Madison Metropolitan School District
(608) 663-1916
cburch at madison.k12.wi.us
More information about the DBIx-Class
mailing list