in reply to Get top N rows in each group with DBIx::Class

Try using the 'rows' attribute, like this:
my $rs = $schema->resultset('Artist')->search( undef, { rows => 10, } );
The Documentation says:

rows
Value: $rows

Specifies the maximum number of rows for direct retrieval or the number of rows per page if the page attribute or method is used.

                All power corrupts, but we need electricity.

Replies are listed 'Best First'.
Re^2: Get top N rows in each group with DBIx::Class
by 1nickt (Canon) on Nov 26, 2017 at 03:18 UTC

    Hi NetWallah, thanks for your reply. If I understand correctly rows basically implements a LIMIT on the query, which isn't quite what I need here. I'm looking for a limit per artist, or, maybe a better example, I want to query for all tracks in the library but limit the results returned to N per CD.

    On a related note, can you say when it's best to use the rows attribute on a search() call, and when it's best to use a slice() call instead?


    The way forward always starts with a minimal test.