Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
aa1b0391
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,发现更多精彩内容 >>
提交
aa1b0391
编写于
8月 11, 2017
作者:
R
Rafael França
提交者:
GitHub
8月 11, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #29720 from gaurish/ar_find_error_message_improvement
Return Not found Ids in ActiveRecord::NotFound
上级
043f83fe
702e36e2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
11 addition
and
7 deletion
+11
-7
activerecord/lib/active_record/associations/collection_association.rb
.../lib/active_record/associations/collection_association.rb
+3
-1
activerecord/lib/active_record/relation/finder_methods.rb
activerecord/lib/active_record/relation/finder_methods.rb
+3
-3
activerecord/test/cases/associations/has_many_through_associations_test.rb
.../cases/associations/has_many_through_associations_test.rb
+4
-2
activerecord/test/cases/finder_test.rb
activerecord/test/cases/finder_test.rb
+1
-1
未找到文件。
activerecord/lib/active_record/associations/collection_association.rb
浏览文件 @
aa1b0391
...
...
@@ -59,7 +59,9 @@ def ids_writer(ids)
r
.
send
(
reflection
.
association_primary_key
)
end
.
values_at
(
*
ids
).
compact
if
records
.
size
!=
ids
.
size
klass
.
all
.
raise_record_not_found_exception!
(
ids
,
records
.
size
,
ids
.
size
,
reflection
.
association_primary_key
)
found_ids
=
records
.
map
{
|
record
|
record
.
send
(
reflection
.
association_primary_key
)
}
not_found_ids
=
ids
-
found_ids
klass
.
all
.
raise_record_not_found_exception!
(
ids
,
records
.
size
,
ids
.
size
,
reflection
.
association_primary_key
,
not_found_ids
)
else
replace
(
records
)
end
...
...
activerecord/lib/active_record/relation/finder_methods.rb
浏览文件 @
aa1b0391
...
...
@@ -330,7 +330,7 @@ def exists?(conditions = :none)
# of results obtained should be provided in the +result_size+ argument and
# the expected number of results should be provided in the +expected_size+
# argument.
def
raise_record_not_found_exception!
(
ids
=
nil
,
result_size
=
nil
,
expected_size
=
nil
,
key
=
primary_key
)
# :nodoc:
def
raise_record_not_found_exception!
(
ids
=
nil
,
result_size
=
nil
,
expected_size
=
nil
,
key
=
primary_key
,
not_found_ids
=
nil
)
# :nodoc:
conditions
=
arel
.
where_sql
(
@klass
)
conditions
=
" [
#{
conditions
}
]"
if
conditions
name
=
@klass
.
name
...
...
@@ -344,8 +344,8 @@ def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_siz
raise
RecordNotFound
.
new
(
error
,
name
,
key
,
ids
)
else
error
=
"Couldn't find all
#{
name
.
pluralize
}
with '
#{
key
}
': "
.
dup
error
<<
"(
#{
ids
.
join
(
", "
)
}
)
#{
conditions
}
(found
#{
result_size
}
results, but was looking for
#{
expected_size
}
)"
error
<<
"(
#{
ids
.
join
(
", "
)
}
)
#{
conditions
}
(found
#{
result_size
}
results, but was looking for
#{
expected_size
}
)
.
"
error
<<
" Couldn't find
#{
name
.
pluralize
(
not_found_ids
.
size
)
}
with
#{
key
.
to_s
.
pluralize
(
not_found_ids
.
size
)
}
#{
not_found_ids
.
join
(
', '
)
}
."
if
not_found_ids
raise
RecordNotFound
.
new
(
error
,
name
,
primary_key
,
ids
)
end
end
...
...
activerecord/test/cases/associations/has_many_through_associations_test.rb
浏览文件 @
aa1b0391
...
...
@@ -891,7 +891,8 @@ def test_collection_singular_ids_setter_raises_exception_when_invalid_ids_set
company
=
companies
(
:rails_core
)
ids
=
[
Developer
.
first
.
id
,
-
9999
]
e
=
assert_raises
(
ActiveRecord
::
RecordNotFound
)
{
company
.
developer_ids
=
ids
}
assert_match
(
/Couldn't find all Developers with 'id'/
,
e
.
message
)
msg
=
"Couldn't find all Developers with 'id': (1, -9999) (found 1 results, but was looking for 2). Couldn't find Developer with id -9999."
assert_equal
(
msg
,
e
.
message
)
end
def
test_collection_singular_ids_setter_raises_exception_when_invalid_ids_set_with_changed_primary_key
...
...
@@ -905,7 +906,8 @@ def test_collection_singular_ids_through_setter_raises_exception_when_invalid_id
author
=
authors
(
:david
)
ids
=
[
categories
(
:general
).
name
,
"Unknown"
]
e
=
assert_raises
(
ActiveRecord
::
RecordNotFound
)
{
author
.
essay_category_ids
=
ids
}
assert_equal
"Couldn't find all Categories with 'name': (General, Unknown) (found 1 results, but was looking for 2)"
,
e
.
message
msg
=
"Couldn't find all Categories with 'name': (General, Unknown) (found 1 results, but was looking for 2). Couldn't find Category with name Unknown."
assert_equal
msg
,
e
.
message
end
def
test_build_a_model_from_hm_through_association_with_where_clause
...
...
activerecord/test/cases/finder_test.rb
浏览文件 @
aa1b0391
...
...
@@ -1153,7 +1153,7 @@ def test_find_some_message_with_custom_primary_key
e
=
assert_raises
(
ActiveRecord
::
RecordNotFound
)
do
model
.
find
"Hello"
,
"World!"
end
assert_equal
"Couldn't find all MercedesCars with 'name': (Hello, World!) (found 0 results, but was looking for 2)"
,
e
.
message
assert_equal
"Couldn't find all MercedesCars with 'name': (Hello, World!) (found 0 results, but was looking for 2)
.
"
,
e
.
message
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录