Changeset 2459

Show
Ignore:
Timestamp:
05/29/08 17:22:32 (21 months ago)
Author:
bchoate
Message:

Adding support for a max_group_by method. BugId:79914

Location:
branches/release-39/lib/MT
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/release-39/lib/MT/Object.pm

    r2453 r2459  
    707707sub sum_group_by   { shift->_proxy('sum_group_by',   @_) } 
    708708sub avg_group_by   { shift->_proxy('avg_group_by',   @_) } 
     709sub max_group_by   { shift->_proxy('max_group_by',   @_) } 
    709710sub remove_all     { shift->_proxy('remove_all',     @_) } 
    710711 
     
    20412042        avg => 'property_to_average' }) 
    20422043 
     2044=head2 Max by Group 
     2045 
     2046=over 4 
     2047 
     2048=item * Class->max_group_by() 
     2049 
     2050=back 
     2051 
     2052Like the count_group_by method, you can select objects from a MT::Object 
     2053store using a SQL 'MAX' operator. 
     2054 
     2055    my $iter = MT::Foo->max_group_by($terms, {%args, group => $group_exprs, 
     2056        max => 'column_name' }) 
     2057 
    20432058=head2 Sum by Group 
    20442059 
  • branches/release-39/lib/MT/ObjectDriver/Driver/DBI.pm

    r2202 r2459  
    116116    $args->{direction} = 'descend' unless exists $args->{direction}; 
    117117    $driver->_do_group_by("AVG($avg_column) AS avg_$avg_column", @_); 
     118} 
     119 
     120sub max_group_by { 
     121    my $driver = shift; 
     122    my ($class, $terms, $args) = @_; 
     123 
     124    my $max_column = delete $args->{max}; 
     125    return unless $max_column; 
     126    $max_column = $driver->_decorate_column_name($class, $max_column); 
     127    $args->{sort} = "max_$max_column" unless exists $args->{sort}; 
     128    $args->{direction} = 'descend' unless exists $args->{direction}; 
     129    $driver->_do_group_by("MAX($max_column) AS max_$max_column", @_); 
    118130} 
    119131