Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
679626e4
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,发现更多精彩内容 >>
提交
679626e4
编写于
6月 23, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15878 from sgrif/sg-null-column
Revert #15502, and add a deprecation warning instead.
上级
c73f97b0
ae96f229
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
18 addition
and
33 deletion
+18
-33
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+2
-1
activerecord/lib/active_record/associations/preloader/association.rb
...d/lib/active_record/associations/preloader/association.rb
+2
-2
activerecord/lib/active_record/attribute_methods.rb
activerecord/lib/active_record/attribute_methods.rb
+10
-6
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+0
-6
activerecord/test/cases/reflection_test.rb
activerecord/test/cases/reflection_test.rb
+4
-18
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
679626e4
...
...
@@ -117,7 +117,8 @@
*Lauro Caetano*, *Carlos Antonio da Silva*
*
Return a null column from
`column_for_attribute`
when no column exists.
*
Deprecate returning
`nil`
from
`column_for_attribute`
when no column exists.
It will return a null object in Rails 5.0
*Sean Griffin*
...
...
activerecord/lib/active_record/associations/preloader/association.rb
浏览文件 @
679626e4
...
...
@@ -104,11 +104,11 @@ def key_conversion_required?
end
def
association_key_type
@klass
.
column_for_attribute
(
association_key_name
).
type
@klass
.
type_for_attribute
(
association_key_name
.
to_s
).
type
end
def
owner_key_type
@model
.
column_for_attribute
(
owner_key_name
).
type
@model
.
type_for_attribute
(
owner_key_name
.
to_s
).
type
end
def
load_slices
(
slices
)
...
...
activerecord/lib/active_record/attribute_methods.rb
浏览文件 @
679626e4
...
...
@@ -186,8 +186,7 @@ def attribute_names
end
# Returns the column object for the named attribute.
# Returns a +ActiveRecord::ConnectionAdapters::NullColumn+ if the
# named attribute does not exist.
# Returns nil if the named attribute does not exist.
#
# class Person < ActiveRecord::Base
# end
...
...
@@ -197,12 +196,17 @@ def attribute_names
# # => #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x007ff4ab083980 @name="name", @sql_type="varchar(255)", @null=true, ...>
#
# person.column_for_attribute(:nothing)
# # =>
#<ActiveRecord::ConnectionAdapters::NullColumn:0xXXX @name=nil, @sql_type=nil, @cast_type=#<Type::Value>, ...>
# # =>
nil
def
column_for_attribute
(
name
)
name
=
name
.
to_s
columns_hash
.
fetch
(
name
)
do
ConnectionAdapters
::
NullColumn
.
new
(
name
)
column
=
columns_hash
[
name
.
to_s
]
if
column
.
nil?
ActiveSupport
::
Deprecation
.
warn
(
<<-
MESSAGE
.
strip_heredoc
)
`column_for_attribute` will return a null object for non-existent columns
in Rails 5.0. If you would like to continue to receive `nil`, you should
instead call `model.class.columns_hash[name]`
MESSAGE
end
column
end
end
...
...
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
679626e4
...
...
@@ -57,12 +57,6 @@ def with_type(type)
end
end
end
class
NullColumn
<
Column
def
initialize
(
name
)
super
name
,
nil
,
Type
::
Value
.
new
end
end
end
# :startdoc:
end
activerecord/test/cases/reflection_test.rb
浏览文件 @
679626e4
...
...
@@ -80,24 +80,10 @@ def test_integer_columns
assert_equal
:integer
,
@first
.
column_for_attribute
(
"id"
).
type
end
def
test_non_existent_columns_return_null_object
column
=
@first
.
column_for_attribute
(
"attribute_that_doesnt_exist"
)
assert_instance_of
ActiveRecord
::
ConnectionAdapters
::
NullColumn
,
column
assert_equal
"attribute_that_doesnt_exist"
,
column
.
name
assert_equal
nil
,
column
.
sql_type
assert_equal
nil
,
column
.
type
assert_not
column
.
number?
assert_not
column
.
text?
assert_not
column
.
binary?
end
def
test_non_existent_columns_are_identity_types
column
=
@first
.
column_for_attribute
(
"attribute_that_doesnt_exist"
)
object
=
Object
.
new
assert_equal
object
,
column
.
type_cast_from_database
(
object
)
assert_equal
object
,
column
.
type_cast_from_user
(
object
)
assert_equal
object
,
column
.
type_cast_for_database
(
object
)
def
test_non_existent_columns_return_nil
assert_deprecated
do
assert_nil
@first
.
column_for_attribute
(
"attribute_that_doesnt_exist"
)
end
end
def
test_reflection_klass_for_nested_class_name
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录