Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dacfa5b7
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
dacfa5b7
编写于
8月 07, 2019
作者:
G
Gannon McGibbon
提交者:
GitHub
8月 07, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #36847 from gmcgibbon/fix_custom_pk_through_reflect
Ensure custom PK types are casted in through reflection queries
上级
d580d8c6
5ec2f35f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
1 deletion
+26
-1
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/reflection.rb
activerecord/lib/active_record/reflection.rb
+10
-1
activerecord/test/cases/reflection_test.rb
activerecord/test/cases/reflection_test.rb
+8
-0
activerecord/test/models/dashboard.rb
activerecord/test/models/dashboard.rb
+2
-0
activerecord/test/models/subscriber.rb
activerecord/test/models/subscriber.rb
+1
-0
activerecord/test/models/subscription.rb
activerecord/test/models/subscription.rb
+1
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
dacfa5b7
*
Ensure custom PK types are casted in through reflection queries.
*Gannon McGibbon*
*
Preserve user supplied joins order as much as possible.
Fixes #36761, #34328, #24281, #12953.
...
...
activerecord/lib/active_record/reflection.rb
浏览文件 @
dacfa5b7
...
...
@@ -764,7 +764,16 @@ def through_reflection?
end
def
klass
@klass
||=
delegate_reflection
.
compute_class
(
class_name
)
@klass
||=
delegate_reflection
.
compute_class
(
class_name
).
tap
do
|
klass
|
if
!
parent_reflection
.
is_a?
(
HasAndBelongsToManyReflection
)
&&
!
klass
.
reflections
.
include?
(
options
[
:through
].
to_s
)
&&
active_record
.
type_for_attribute
(
active_record
.
primary_key
).
type
!=
:integer
raise
NotImplementedError
,
<<~
MSG
.
squish
In order to correctly type cast
#{
active_record
}
.
#{
active_record
.
primary_key
}
,
#{
klass
}
needs to define a :
#{
options
[
:through
]
}
association.
MSG
end
end
end
# Returns the source of the through reflection. It checks both a singularized
...
...
activerecord/test/cases/reflection_test.rb
浏览文件 @
dacfa5b7
...
...
@@ -256,6 +256,14 @@ def test_has_many_through_reflection
assert_kind_of
ThroughReflection
,
Subscriber
.
reflect_on_association
(
:books
)
end
def
test_uncastable_has_many_through_reflection
error
=
assert_raises
(
NotImplementedError
)
{
Subscriber
.
new
.
published_books
}
assert_equal
<<~
MSG
.
squish
,
error
.
message
In order to correctly type cast Subscriber.nick,
PublishedBook needs to define a :subscriptions association.
MSG
end
def
test_chain
expected
=
[
Organization
.
reflect_on_association
(
:author_essay_categories
),
...
...
activerecord/test/models/dashboard.rb
浏览文件 @
dacfa5b7
...
...
@@ -2,4 +2,6 @@
class
Dashboard
<
ActiveRecord
::
Base
self
.
primary_key
=
:dashboard_id
has_one
:speedometer
end
activerecord/test/models/subscriber.rb
浏览文件 @
dacfa5b7
...
...
@@ -4,6 +4,7 @@ class Subscriber < ActiveRecord::Base
self
.
primary_key
=
"nick"
has_many
:subscriptions
has_many
:books
,
through: :subscriptions
has_many
:published_books
,
through: :subscriptions
end
class
SpecialSubscriber
<
Subscriber
...
...
activerecord/test/models/subscription.rb
浏览文件 @
dacfa5b7
...
...
@@ -2,6 +2,7 @@
class
Subscription
<
ActiveRecord
::
Base
belongs_to
:subscriber
,
counter_cache: :books_count
belongs_to
:published_book
belongs_to
:book
validates_presence_of
:subscriber_id
,
:book_id
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录