Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6717d602
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6717d602
编写于
2月 28, 2018
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #31966 from kg8m/fix_limited_ids_for
Use column alias of primary_key in limited_ids_for
上级
0605f45a
2d48268d
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
30 addition
and
17 deletion
+30
-17
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+8
-0
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+1
-1
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
...ecord/connection_adapters/postgresql/schema_statements.rb
+1
-1
activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb
...erecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb
+5
-5
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
...test/cases/adapters/postgresql/postgresql_adapter_test.rb
+10
-10
activerecord/test/cases/finder_test.rb
activerecord/test/cases/finder_test.rb
+5
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
6717d602
## Rails 6.0.0.alpha (Unreleased) ##
*
Fix
`#columsn_for_distinct`
of MySQL and PostgreSQL to make
`ActiveRecord::FinderMethods#limited_ids_for`
use correct primary key values
even if
`ORDER BY`
columns include other table's primary key.
Fixes #28364.
*Takumi Kagiyama*
*
Make
`reflection.klass`
raise if
`polymorphic?`
not to be misused.
Fixes #31876.
...
...
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
6717d602
...
...
@@ -513,7 +513,7 @@ def columns_for_distinct(columns, orders) # :nodoc:
s
.
gsub
(
/\s+(?:ASC|DESC)\b/i
,
""
)
}.
reject
(
&
:blank?
).
map
.
with_index
{
|
column
,
i
|
"
#{
column
}
AS alias_
#{
i
}
"
}
[
super
,
*
order_columns
]
.
join
(
", "
)
(
order_columns
<<
super
)
.
join
(
", "
)
end
def
strict_mode?
...
...
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
浏览文件 @
6717d602
...
...
@@ -583,7 +583,7 @@ def columns_for_distinct(columns, orders) #:nodoc:
.
gsub
(
/\s+NULLS\s+(?:FIRST|LAST)\b/i
,
""
)
}.
reject
(
&
:blank?
).
map
.
with_index
{
|
column
,
i
|
"
#{
column
}
AS alias_
#{
i
}
"
}
[
super
,
*
order_columns
]
.
join
(
", "
)
(
order_columns
<<
super
)
.
join
(
", "
)
end
def
update_table_definition
(
table_name
,
base
)
# :nodoc:
...
...
activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb
浏览文件 @
6717d602
...
...
@@ -25,25 +25,25 @@ def test_columns_for_distinct_zero_orders
end
def
test_columns_for_distinct_one_order
assert_equal
"posts.
id, posts.created_at AS alias_0
"
,
assert_equal
"posts.
created_at AS alias_0, posts.id
"
,
@conn
.
columns_for_distinct
(
"posts.id"
,
[
"posts.created_at desc"
])
end
def
test_columns_for_distinct_few_orders
assert_equal
"posts.
id, posts.created_at AS alias_0, posts.position AS alias_1
"
,
assert_equal
"posts.
created_at AS alias_0, posts.position AS alias_1, posts.id
"
,
@conn
.
columns_for_distinct
(
"posts.id"
,
[
"posts.created_at desc"
,
"posts.position asc"
])
end
def
test_columns_for_distinct_with_case
assert_equal
(
"
posts.id, CASE WHEN author.is_active THEN UPPER(author.name) ELSE UPPER(author.email) END AS alias_0
"
,
"
CASE WHEN author.is_active THEN UPPER(author.name) ELSE UPPER(author.email) END AS alias_0, posts.id
"
,
@conn
.
columns_for_distinct
(
"posts.id"
,
[
"CASE WHEN author.is_active THEN UPPER(author.name) ELSE UPPER(author.email) END"
])
)
end
def
test_columns_for_distinct_blank_not_nil_orders
assert_equal
"posts.
id, posts.created_at AS alias_0
"
,
assert_equal
"posts.
created_at AS alias_0, posts.id
"
,
@conn
.
columns_for_distinct
(
"posts.id"
,
[
"posts.created_at desc"
,
""
,
" "
])
end
...
...
@@ -52,7 +52,7 @@ def test_columns_for_distinct_with_arel_order
def
order
.
to_sql
"posts.created_at desc"
end
assert_equal
"posts.
id, posts.created_at AS alias_0
"
,
assert_equal
"posts.
created_at AS alias_0, posts.id
"
,
@conn
.
columns_for_distinct
(
"posts.id"
,
[
order
])
end
...
...
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
浏览文件 @
6717d602
...
...
@@ -263,25 +263,25 @@ def test_columns_for_distinct_zero_orders
end
def
test_columns_for_distinct_one_order
assert_equal
"posts.
id, posts.created_at AS alias_0
"
,
assert_equal
"posts.
created_at AS alias_0, posts.id
"
,
@connection
.
columns_for_distinct
(
"posts.id"
,
[
"posts.created_at desc"
])
end
def
test_columns_for_distinct_few_orders
assert_equal
"posts.
id, posts.created_at AS alias_0, posts.position AS alias_1
"
,
assert_equal
"posts.
created_at AS alias_0, posts.position AS alias_1, posts.id
"
,
@connection
.
columns_for_distinct
(
"posts.id"
,
[
"posts.created_at desc"
,
"posts.position asc"
])
end
def
test_columns_for_distinct_with_case
assert_equal
(
"
posts.id, CASE WHEN author.is_active THEN UPPER(author.name) ELSE UPPER(author.email) END AS alias_0
"
,
"
CASE WHEN author.is_active THEN UPPER(author.name) ELSE UPPER(author.email) END AS alias_0, posts.id
"
,
@connection
.
columns_for_distinct
(
"posts.id"
,
[
"CASE WHEN author.is_active THEN UPPER(author.name) ELSE UPPER(author.email) END"
])
)
end
def
test_columns_for_distinct_blank_not_nil_orders
assert_equal
"posts.
id, posts.created_at AS alias_0
"
,
assert_equal
"posts.
created_at AS alias_0, posts.id
"
,
@connection
.
columns_for_distinct
(
"posts.id"
,
[
"posts.created_at desc"
,
""
,
" "
])
end
...
...
@@ -290,23 +290,23 @@ def test_columns_for_distinct_with_arel_order
def
order
.
to_sql
"posts.created_at desc"
end
assert_equal
"posts.
id, posts.created_at AS alias_0
"
,
assert_equal
"posts.
created_at AS alias_0, posts.id
"
,
@connection
.
columns_for_distinct
(
"posts.id"
,
[
order
])
end
def
test_columns_for_distinct_with_nulls
assert_equal
"posts.
title, posts.updater_id AS alias_0
"
,
@connection
.
columns_for_distinct
(
"posts.title"
,
[
"posts.updater_id desc nulls first"
])
assert_equal
"posts.
title, posts.updater_id AS alias_0
"
,
@connection
.
columns_for_distinct
(
"posts.title"
,
[
"posts.updater_id desc nulls last"
])
assert_equal
"posts.
updater_id AS alias_0, posts.title
"
,
@connection
.
columns_for_distinct
(
"posts.title"
,
[
"posts.updater_id desc nulls first"
])
assert_equal
"posts.
updater_id AS alias_0, posts.title
"
,
@connection
.
columns_for_distinct
(
"posts.title"
,
[
"posts.updater_id desc nulls last"
])
end
def
test_columns_for_distinct_without_order_specifiers
assert_equal
"posts.
title, posts.updater_id AS alias_0
"
,
assert_equal
"posts.
updater_id AS alias_0, posts.title
"
,
@connection
.
columns_for_distinct
(
"posts.title"
,
[
"posts.updater_id"
])
assert_equal
"posts.
title, posts.updater_id AS alias_0
"
,
assert_equal
"posts.
updater_id AS alias_0, posts.title
"
,
@connection
.
columns_for_distinct
(
"posts.title"
,
[
"posts.updater_id nulls last"
])
assert_equal
"posts.
title, posts.updater_id AS alias_0
"
,
assert_equal
"posts.
updater_id AS alias_0, posts.title
"
,
@connection
.
columns_for_distinct
(
"posts.title"
,
[
"posts.updater_id nulls first"
])
end
...
...
activerecord/test/cases/finder_test.rb
浏览文件 @
6717d602
...
...
@@ -1189,6 +1189,11 @@ def test_find_with_order_on_included_associations_with_construct_finder_sql_for_
order
(
"author_addresses_authors.id DESC"
).
limit
(
3
).
to_a
.
size
end
def
test_find_with_eager_loading_collection_and_ordering_by_collection_primary_key
assert_equal
Post
.
first
,
Post
.
eager_load
(
comments: :ratings
).
order
(
"posts.id, ratings.id, comments.id"
).
first
end
def
test_find_with_nil_inside_set_passed_for_one_attribute
client_of
=
Company
.
where
(
client_of:
[
2
,
1
,
nil
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录