I'm trying to work out a way of executing a ResultSet query mutiple times with a different parameter, but despite searching everywhere, I can't find anything that covers the subject.
I have a reasonably complex query:
my $items = $self->db->resultset('Item')->search({},{ '+select' => ... 'join' => ... where => { -or => ... 'start_datetime' => {'<=' => \'NOW()'}, 'end_datetime' => {'>=' => \'NOW()'}, }, group_by => ... order_by => ... });
But I want to get the results multiple times in a loop:
foreach my $value(@values) { my $results = $items->search({ 'joined_table.column' => $value }); # Process and output results of this search ... }
I'd rather not have the query re-prepared multiple times when the only thing that has changed is one piece of data. Is DBIx clever enough to realise that it has created the same underlying query twice and not re-prepare it?
I'm assuming no.
If not, how could I do something like this?
my $results_query = $items->search({ 'joined_table.column' => '?' }); foreach my $value(@values) { my $results = $results_query->bind($value); # Process and output results of this search ... }
The only reference to this sort of thing that I can find is by creating a ResultSource::View class, which seems like overkill just for the sake of some bind parameters.
In reply to Re-using DBIx ResultSet with different parameters by MattLG
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |