Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8587cf0d
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,发现更多精彩内容 >>
提交
8587cf0d
编写于
9月 24, 2015
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21720 from byroot/ignore-columns
Implement ActiveRecord::Base.ignored_columns
上级
4a375a83
4ccdd412
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
37 addition
and
1 deletion
+37
-1
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/model_schema.rb
activerecord/lib/active_record/model_schema.rb
+8
-1
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+18
-0
activerecord/test/models/developer.rb
activerecord/test/models/developer.rb
+5
-0
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+1
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
8587cf0d
...
...
@@ -32,6 +32,11 @@
*Yves Senn*, *Matthew Draper*
*
Add
`ActiveRecord::Base.ignored_columns`
to make some columns
invisible from ActiveRecord.
*Jean Boussier*
*
`ActiveRecord::Tasks::MySQLDatabaseTasks`
fails if shellout to
mysql commands (like
`mysqldump`
) is not successful.
...
...
activerecord/lib/active_record/model_schema.rb
浏览文件 @
8587cf0d
...
...
@@ -50,6 +50,13 @@ module ModelSchema
class_attribute
:pluralize_table_names
,
instance_writer:
false
self
.
pluralize_table_names
=
true
##
# :singleton-method:
# Accessor for the list of columns names the model should ignore. Ignored columns won't have attribute
# accessors defined, and won't be referenced in SQL queries.
class_attribute
:ignored_columns
,
instance_accessor:
false
self
.
ignored_columns
=
[].
freeze
self
.
inheritance_column
=
'type'
delegate
:type_for_attribute
,
to: :class
...
...
@@ -308,7 +315,7 @@ def load_schema
end
def
load_schema!
@columns_hash
=
connection
.
schema_cache
.
columns_hash
(
table_name
)
@columns_hash
=
connection
.
schema_cache
.
columns_hash
(
table_name
)
.
except
(
*
ignored_columns
)
@columns_hash
.
each
do
|
name
,
column
|
warn_if_deprecated_type
(
column
)
define_attribute
(
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
8587cf0d
...
...
@@ -1571,4 +1571,22 @@ def test_default_values_are_deeply_dupped
assert_not
topic
.
id_changed?
end
test
"ignored columns are not present in columns_hash"
do
cache_columns
=
Developer
.
connection
.
schema_cache
.
columns_hash
(
Developer
.
table_name
)
assert_includes
cache_columns
.
keys
,
'first_name'
refute_includes
Developer
.
columns_hash
.
keys
,
'first_name'
end
test
"ignored columns have no attirbute methods"
do
refute
Developer
.
new
.
respond_to?
(
:first_name
)
refute
Developer
.
new
.
respond_to?
(
:first_name
=
)
refute
Developer
.
new
.
respond_to?
(
:first_name?
)
end
test
"ignored columns don't prevent explicit declaration of attribute methods"
do
assert
Developer
.
new
.
respond_to?
(
:last_name
)
assert
Developer
.
new
.
respond_to?
(
:last_name
=
)
assert
Developer
.
new
.
respond_to?
(
:last_name?
)
end
end
activerecord/test/models/developer.rb
浏览文件 @
8587cf0d
...
...
@@ -7,6 +7,8 @@ def find_least_recent
end
class
Developer
<
ActiveRecord
::
Base
self
.
ignored_columns
=
%w(first_name last_name)
has_and_belongs_to_many
:projects
do
def
find_most_recent
order
(
"id DESC"
).
first
...
...
@@ -61,6 +63,9 @@ def find_least_recent
developer
.
audit_logs
.
build
:message
=>
"Computer created"
end
attr_accessor
:last_name
define_attribute_method
'last_name'
def
log
=
(
message
)
audit_logs
.
build
:message
=>
message
end
...
...
activerecord/test/schema/schema.rb
浏览文件 @
8587cf0d
...
...
@@ -250,6 +250,7 @@ def except(adapter_names_to_exclude)
create_table
:developers
,
force:
true
do
|
t
|
t
.
string
:name
t
.
string
:first_name
t
.
integer
:salary
,
default:
70000
if
subsecond_precision_supported?
t
.
datetime
:created_at
,
precision:
6
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录