Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f437f110
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,发现更多精彩内容 >>
提交
f437f110
编写于
6月 26, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15924 from sgrif/sg-write-unknown-column
Move writing unknown column exception to null attribute
上级
8b0753b4
3bc314e6
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
34 addition
and
13 deletion
+34
-13
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/attribute.rb
activerecord/lib/active_record/attribute.rb
+5
-0
activerecord/lib/active_record/attribute_methods/primary_key.rb
...record/lib/active_record/attribute_methods/primary_key.rb
+2
-5
activerecord/lib/active_record/attribute_methods/write.rb
activerecord/lib/active_record/attribute_methods/write.rb
+0
-4
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+1
-1
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+1
-1
activerecord/test/cases/attribute_methods_test.rb
activerecord/test/cases/attribute_methods_test.rb
+9
-0
activerecord/test/cases/primary_keys_test.rb
activerecord/test/cases/primary_keys_test.rb
+10
-2
activerecord/test/models/contact.rb
activerecord/test/models/contact.rb
+1
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
f437f110
*
Fix subtle bugs regarding attribute assignment on models with no primary
key.
`'id'`
will no longer be part of the attributes hash.
*Sean Griffin*
*
Deprecate automatic counter caches on
`has_many :through`
. The behavior was
broken and inconsistent.
...
...
activerecord/lib/active_record/attribute.rb
浏览文件 @
f437f110
...
...
@@ -90,6 +90,11 @@ def initialize(name)
def
value
nil
end
def
with_value_from_database
(
value
)
raise
ActiveModel
::
MissingAttributeError
,
"can't write unknown attribute `
#{
name
}
`"
end
alias_method
:with_value_from_user
,
:with_value_from_database
end
class
Uninitialized
<
Attribute
# :nodoc:
...
...
activerecord/lib/active_record/attribute_methods/primary_key.rb
浏览文件 @
f437f110
...
...
@@ -83,12 +83,9 @@ def reset_primary_key #:nodoc:
end
def
get_primary_key
(
base_name
)
#:nodoc:
return
'id'
if
base_name
.
blank?
case
primary_key_prefix_type
when
:table_name
if
base_name
&&
primary_key_prefix_type
==
:table_name
base_name
.
foreign_key
(
false
)
when
:table_name_with_underscore
elsif
base_name
&&
primary_key_prefix_type
==
:table_name_with_underscore
base_name
.
foreign_key
else
if
ActiveRecord
::
Base
!=
self
&&
table_exists?
...
...
activerecord/lib/active_record/attribute_methods/write.rb
浏览文件 @
f437f110
...
...
@@ -70,10 +70,6 @@ def write_attribute_with_type_cast(attr_name, value, should_type_cast)
attr_name
=
attr_name
.
to_s
attr_name
=
self
.
class
.
primary_key
if
attr_name
==
'id'
&&
self
.
class
.
primary_key
unless
has_attribute?
(
attr_name
)
||
self
.
class
.
columns_hash
.
key?
(
attr_name
)
raise
ActiveModel
::
MissingAttributeError
,
"can't write unknown attribute `
#{
attr_name
}
'"
end
if
should_type_cast
@attributes
.
write_from_user
(
attr_name
,
value
)
else
...
...
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
f437f110
...
...
@@ -381,7 +381,7 @@ def tables(name = nil, database = nil, like = nil) #:nodoc:
end
def
table_exists?
(
name
)
return
false
unless
name
return
false
unless
name
.
present?
return
true
if
tables
(
nil
,
nil
,
name
).
any?
name
=
name
.
to_s
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
f437f110
...
...
@@ -521,7 +521,7 @@ def to_ary # :nodoc:
def
init_internals
pk
=
self
.
class
.
primary_key
unless
@attributes
.
include?
(
pk
)
if
pk
&&
!
@attributes
.
include?
(
pk
)
@attributes
.
write_from_database
(
pk
,
nil
)
end
...
...
activerecord/test/cases/attribute_methods_test.rb
浏览文件 @
f437f110
...
...
@@ -253,6 +253,15 @@ def test_case_sensitive_attributes_hash
assert_equal
@loaded_fixtures
[
'computers'
][
'workstation'
].
to_hash
,
Computer
.
first
.
attributes
end
def
test_attributes_without_primary_key
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
do
self
.
table_name
=
'developers_projects'
end
assert_equal
klass
.
column_names
,
klass
.
new
.
attributes
.
keys
assert_not
klass
.
new
.
attributes
.
key?
(
'id'
)
end
def
test_hashes_not_mangled
new_topic
=
{
:title
=>
"New Topic"
}
new_topic_values
=
{
:title
=>
"AnotherTopic"
}
...
...
activerecord/test/cases/primary_keys_test.rb
浏览文件 @
f437f110
...
...
@@ -134,14 +134,22 @@ def test_supports_primary_key
end
def
test_primary_key_returns_value_if_it_exists
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
do
self
.
table_name
=
'developers'
end
if
ActiveRecord
::
Base
.
connection
.
supports_primary_key?
assert_equal
'id'
,
ActiveRecord
::
Base
.
connection
.
primary_key
(
'developers'
)
assert_equal
'id'
,
klass
.
primary_key
end
end
def
test_primary_key_returns_nil_if_it_does_not_exist
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
do
self
.
table_name
=
'developers_projects'
end
if
ActiveRecord
::
Base
.
connection
.
supports_primary_key?
assert_nil
ActiveRecord
::
Base
.
connection
.
primary_key
(
'developers_projects'
)
assert_nil
klass
.
primary_key
end
end
...
...
activerecord/test/models/contact.rb
浏览文件 @
f437f110
...
...
@@ -8,6 +8,7 @@ def self.extended(base)
table_name
=>
'id'
}
column
:id
,
:integer
column
:name
,
:string
column
:age
,
:integer
column
:avatar
,
:binary
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录