Skip to content

Commit 8bc5d73

Browse files
committed
Make sure primary keys are used for pagination even when natural and last column. Closes #123
1 parent d30b45a commit 8bc5d73

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

test/cases/specific_schema_test_sqlserver.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
6262
assert record.save
6363
assert_equal 12, record.reload.id
6464
end
65+
66+
should 'use primary key for row table order in pagination sql' do
67+
sql = /OVER \(ORDER BY \[natural_pk_data\]\.\[legacy_id\] ASC\)/
68+
assert_sql(sql) { SqlServerNaturalPkData.limit(5).offset(5).all }
69+
end
6570

6671
end
6772

test/cases/sqlserver_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FloatData < ActiveRecord::Base ; self.table_name = 'float_data' ; end
3939
class CustomersView < ActiveRecord::Base ; self.table_name = 'customers_view' ; end
4040
class StringDefaultsView < ActiveRecord::Base ; self.table_name = 'string_defaults_view' ; end
4141
class StringDefaultsBigView < ActiveRecord::Base ; self.table_name = 'string_defaults_big_view' ; end
42-
class SqlServerNaturalPkData < ActiveRecord::Base ; self.table_name = 'natural_pk_data' ; end
42+
class SqlServerNaturalPkData < ActiveRecord::Base ; self.table_name = 'natural_pk_data' ; self.primary_key = 'legacy_id' ; end
4343
class SqlServerNaturalPkIntData < ActiveRecord::Base ; self.table_name = 'natural_pk_int_data' ; end
4444
class SqlServerNaturalPkDataSchema < ActiveRecord::Base ; self.table_name = 'test.sql_server_schema_natural_id' ; end
4545
class SqlServerQuotedTable < ActiveRecord::Base ; self.table_name = 'quoted-table' ; end

0 commit comments

Comments
 (0)