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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.