Hi Shadowsong, thanks very much for your reply and demo. I had seen that part of the doc and it looks promising, but the problem I am facing is that this filter ('N per "group"') must be applied after some other search calls on the RS.

Continuing the metaphor, this would be something like:

  1. Restrict Artists to given musical genre
  2. Restrict Albums to those release since given date
  3. Restrict results to maximum N Albums per Artist
In my app I have the first two steps handled with methods in My::Schema::ResultSet::CD:
sub by_genre { $_[0]->search({ 'me.genre' => $_[1] }); sub since { $_[0]->search({ 'me.released' => { '>=', $_[1] } });
So the consuming code can do:
my $rs = $schema->resultset('CD'); if ( my $genre = param->{'genre'} ) { $rs = $rs->by_genre( $genre ); } if ( my $since = param->{'since'} ) { $rs = $rs->since( $since ); }
I need to add a method that can act upon the existing ResultSet,
if ( my $limit = param->{'limit'} ) { $rs = $rs->limit_per_artist( $limit ); }
It's not clear to me that the doc you linked to and demoed can be adapted to search an existing RS, but I'll keep experimenting. Thanks again.


The way forward always starts with a minimal test.

In reply to Re^2: Get top N rows in each group with DBIx::Class by 1nickt
in thread Get top N rows in each group with DBIx::Class by 1nickt

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.