Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
baa237c9
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,发现更多精彩内容 >>
提交
baa237c9
编写于
3月 21, 2011
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow to read and write AR attributes with non valid identifiers
上级
da6c7bd4
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
22 addition
and
2 deletion
+22
-2
activerecord/lib/active_record/attribute_methods/read.rb
activerecord/lib/active_record/attribute_methods/read.rb
+4
-1
activerecord/lib/active_record/attribute_methods/write.rb
activerecord/lib/active_record/attribute_methods/write.rb
+3
-1
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+12
-0
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+3
-0
未找到文件。
activerecord/lib/active_record/attribute_methods/read.rb
浏览文件 @
baa237c9
...
@@ -70,7 +70,10 @@ def define_read_method(symbol, attr_name, column)
...
@@ -70,7 +70,10 @@ def define_read_method(symbol, attr_name, column)
if
cache_attribute?
(
attr_name
)
if
cache_attribute?
(
attr_name
)
access_code
=
"@attributes_cache['
#{
attr_name
}
'] ||= (
#{
access_code
}
)"
access_code
=
"@attributes_cache['
#{
attr_name
}
'] ||= (
#{
access_code
}
)"
end
end
generated_attribute_methods
.
module_eval
(
"def _
#{
symbol
}
;
#{
access_code
}
; end; alias
#{
symbol
}
_
#{
symbol
}
"
,
__FILE__
,
__LINE__
)
generated_attribute_methods
.
module_eval
do
define_method
(
"_
#{
symbol
}
"
)
{
eval
(
access_code
)
}
alias_method
(
symbol
,
"_
#{
symbol
}
"
)
end
end
end
end
end
...
...
activerecord/lib/active_record/attribute_methods/write.rb
浏览文件 @
baa237c9
...
@@ -10,7 +10,9 @@ module Write
...
@@ -10,7 +10,9 @@ module Write
module
ClassMethods
module
ClassMethods
protected
protected
def
define_method_attribute
=
(
attr_name
)
def
define_method_attribute
=
(
attr_name
)
generated_attribute_methods
.
module_eval
(
"def
#{
attr_name
}
=(new_value); write_attribute('
#{
attr_name
}
', new_value); end"
,
__FILE__
,
__LINE__
)
generated_attribute_methods
.
send
(
:define_method
,
"
#{
attr_name
}
="
)
do
|
new_value
|
write_attribute
(
attr_name
,
new_value
)
end
end
end
end
end
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
baa237c9
...
@@ -45,6 +45,8 @@ class ReadonlyTitlePost < Post
...
@@ -45,6 +45,8 @@ class ReadonlyTitlePost < Post
attr_readonly
:title
attr_readonly
:title
end
end
class
Weird
<
ActiveRecord
::
Base
;
end
class
Boolean
<
ActiveRecord
::
Base
;
end
class
Boolean
<
ActiveRecord
::
Base
;
end
class
BasicsTest
<
ActiveRecord
::
TestCase
class
BasicsTest
<
ActiveRecord
::
TestCase
...
@@ -477,6 +479,16 @@ def test_readonly_attributes
...
@@ -477,6 +479,16 @@ def test_readonly_attributes
assert_equal
"changed"
,
post
.
body
assert_equal
"changed"
,
post
.
body
end
end
def
test_non_valid_identifier_column_name
weird
=
Weird
.
create
(
'a$b'
=>
'value'
)
weird
.
reload
assert_equal
'value'
,
weird
.
send
(
'a$b'
)
weird
.
update_attribute
(
'a$b'
,
'value2'
)
weird
.
reload
assert_equal
'value2'
,
weird
.
send
(
'a$b'
)
end
def
test_multiparameter_attributes_on_date
def
test_multiparameter_attributes_on_date
attributes
=
{
"last_read(1i)"
=>
"2004"
,
"last_read(2i)"
=>
"6"
,
"last_read(3i)"
=>
"24"
}
attributes
=
{
"last_read(1i)"
=>
"2004"
,
"last_read(2i)"
=>
"6"
,
"last_read(3i)"
=>
"24"
}
topic
=
Topic
.
find
(
1
)
topic
=
Topic
.
find
(
1
)
...
...
activerecord/test/schema/schema.rb
浏览文件 @
baa237c9
...
@@ -690,6 +690,9 @@ def create_table(*args, &block)
...
@@ -690,6 +690,9 @@ def create_table(*args, &block)
t
.
integer
:molecule_id
t
.
integer
:molecule_id
t
.
string
:name
t
.
string
:name
end
end
create_table
:weirds
,
:force
=>
true
do
|
t
|
t
.
string
'a$b'
end
except
'SQLite'
do
except
'SQLite'
do
# fk_test_has_fk should be before fk_test_has_pk
# fk_test_has_fk should be before fk_test_has_pk
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录