From: Peter Rabbitson Date: Tue, 31 Aug 2010 10:19:57 +0000 (+0200) Subject: Make CDBICompat keep a stable oder of columns in each column-group X-Git-Tag: v0.08124~92 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b818efd7cd7db9188d32b1afb7f1081c07278eae;p=dbsrgits%2FDBIx-Class.git Make CDBICompat keep a stable oder of columns in each column-group (was relying on order of %{} until now) --- diff --git a/Changes b/Changes index d23d8b9..a20019f 100644 --- a/Changes +++ b/Changes @@ -26,6 +26,8 @@ Revision history for DBIx::Class (RT#59619) - Fixed t/54taint fails under local-lib - Fixed SELECT ... FOR UPDATE with LIMIT regression (RT#58554) + - Fixed CDBICompat to preserve order of column-group additions, + so that test relying on the order of %{} will no longer fail * Misc - Refactored capability handling in Storage::DBI, allows for diff --git a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm index 3a026b2..d804d02 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm @@ -5,6 +5,7 @@ use strict; use warnings; use Sub::Name (); use Storable 'dclone'; +use List::Util (); use base qw/DBIx::Class::Row/; @@ -19,7 +20,10 @@ sub columns { $class->_add_column_group($group => @_) if @_; return $class->all_columns if $group eq "All"; return $class->primary_column if $group eq "Primary"; - return keys %{$class->_column_groups->{$group}}; + + my $grp = $class->_column_groups->{$group}; + my @grp_cols = sort { $grp->{$b} <=> $grp->{$a} } (keys %$grp); + return @grp_cols; } sub _add_column_group { @@ -43,7 +47,9 @@ sub _register_column_group { if ($group eq 'Primary') { $class->set_primary_key(@cols); - $groups->{'Essential'}{$_} ||= 1 for @cols; + delete $groups->{'Essential'}{$_} for @cols; + my $first = List::Util::max(values %{$groups->{'Essential'}}); + $groups->{'Essential'}{$_} = ++$first for reverse @cols; } if ($group eq 'All') { @@ -56,7 +62,9 @@ sub _register_column_group { } } - $groups->{$group}{$_} ||= 1 for @cols; + delete $groups->{$group}{$_} for @cols; + my $first = List::Util::max(values %{$groups->{$group}}); + $groups->{$group}{$_} = ++$first for reverse @cols; $class->_column_groups($groups); }