Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 068f652c

Von Sven Schöling vor fast 9 Jahren hinzugefügt

  • ID 068f652cd376ffcaa392d2fc32f9d194e17daa44
  • Vorgänger 03087f23
  • Nachfolger 2459db37

GetModels Sorted: tiebreaker für deterministisches sortieren

Unterschiede anzeigen:

SL/DB/Helper/Sorted.pm
27 27

  
28 28
  my $sort_by_str = $sort_spec->{columns}->{$sort_by};
29 29
  $sort_by_str    = [ $sort_by_str ] unless ref($sort_by_str) eq 'ARRAY';
30

  
31
  # generaate tiebreaker
32
  push @$sort_by_str, @{ $sort_spec->{tiebreaker} };
33

  
30 34
  $sort_by_str    = join(', ', map { "${_} ${sort_dir_str}${nulls_str}" } @{ $sort_by_str });
31 35

  
32 36
  return wantarray ? ($sort_by, $sort_dir, $sort_by_str) : $sort_by_str;
......
50 54
  my %sort_spec = defined &{ "${class}::_sort_spec" } ? $class->_sort_spec : ();
51 55

  
52 56
  my $meta = $class->object_class->meta;
57
  my $table = $meta->table;
53 58

  
54 59
  if (!$sort_spec{default}) {
55 60
    my @primary_keys = $meta->primary_key;
......
59 64
  $sort_spec{columns} ||= { SIMPLE => [ map { "$_" } $meta->columns ] };
60 65

  
61 66
  if ($sort_spec{columns}->{SIMPLE}) {
62
    my $table = $meta->table;
63

  
64 67
    if (!ref($sort_spec{columns}->{SIMPLE}) && ($sort_spec{columns}->{SIMPLE} eq 'ALL')) {
65 68
      map { $sort_spec{columns}->{"$_"} ||= "${table}.${_}"} @{ $meta->columns };
66 69
      delete $sort_spec{columns}->{SIMPLE};
......
69 72
    }
70 73
  }
71 74

  
75
  $sort_spec{tiebreaker} ||= [ map { "${table}.${_}" } $meta->primary_key ];
76

  
72 77
  return \%sort_spec;
73 78
}
74 79

  
......
211 216
             default                 => 'LAST',
212 217
           },
213 218

  
219
=item C<tiebreaker>
220

  
221
Optional tiebreaker sorting that gets appended to any user requested sorting.
222
Needed to make sorting by non unique columns deterministic.
223

  
224
If present must be an arrayref of column sort specs (see C<column>).
225

  
226
Defaults to primary keys.
227

  
214 228
=back
215 229

  
216 230
=back

Auch abrufbar als: Unified diff