DBIx::Class - Related Tables

Dagfinn Ilmari Mannsåker ilmari at ilmari.org
Tue Oct 7 02:41:58 BST 2008


"Wallace Reis" <reis.wallace at gmail.com> writes:

> On Mon, Oct 6, 2008 at 5:59 PM, Dave Cross <dave at dave.org.uk> wrote:
>> Given a distribution object, I want to find the highest version for
>> which we have a successful build (or, to find out that there hasn't been
>> a successful build).
>
> my $main_build = $dist->builds->search_rs({
>         'status' => 'success'
> }, {
>         'select' => [{ 'MAX' => 'version' }],
>         'as'       => ['max_version'],
>         'rows'   => '1'
> })->single;
>
> print $main_build->get_column('max_version');
>
> (...)
>
> or
>
> my $main_build = $dist->builds->search_rs({
>         'status' => 'success'
> }, {
>         'order_by' => 'version DESC',
>         'rows'        => '1'
> })->single;
>
> print $main_build->version;

or 

my $max_version = $dist->search_related( builds => { status => 'success' })
                       ->get_column('version')->max;

-- 
ilmari
"A disappointingly low fraction of the human race is,
 at any given time, on fire." - Stig Sandbeck Mathisen


More information about the london.pm mailing list