Skip to content

Commit 9877240

Browse files
committed
Guarantee that rows are always returned in a consistent order.
1 parent 50afb75 commit 9877240

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This file tracks the changes to Wing over time. Especially
44
with respect to new features and compatibility changes.
55
==========================================================
66

7+
2024-08-01
8+
* Guarantee that rows are always returned in a consistent order.
9+
710
2024-04-29
811
* Modernize the install to latest Perl and fix a bunch of perl prereq problems.
912

lib/Wing/DB/ResultSet.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ sub format_list {
137137
# ordering
138138
if (exists $options{order_by} && $options{order_by}) {
139139
my $order_by = $options{order_by};
140+
my $has_id = 0;
140141
if (ref $order_by ne 'ARRAY') {
141142
$order_by = [$order_by];
142143
}
@@ -147,6 +148,10 @@ sub format_list {
147148
next;
148149
}
149150

151+
if ($order_by->[$i] eq 'id' || $order_by->[$i] eq 'me.id' ) {
152+
$has_id = 1;
153+
}
154+
150155
if ($order_by->[$i] !~ m/\./) {
151156
$order_by->[$i] = 'me.'.$order_by->[$i];
152157
}
@@ -158,6 +163,9 @@ sub format_list {
158163
}
159164
}
160165
}
166+
if (! $has_id) {
167+
push @{ $order_by }, 'me.id';
168+
}
161169
$extra->{order_by} = $order_by;
162170
}
163171
if (exists $extra->{order_by} && $extra->{order_by} && exists $options{sort_order} && defined $options{sort_order} && $options{sort_order} eq 'desc') {

0 commit comments

Comments
 (0)