Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b8e1f202
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,发现更多精彩内容 >>
提交
b8e1f202
编写于
2月 02, 2015
作者:
C
Chris Sinjakli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generate consistent names for foreign keys
上级
35d77130
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
3 deletion
+16
-3
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+9
-0
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
..._record/connection_adapters/abstract/schema_statements.rb
+5
-1
activerecord/test/cases/migration/foreign_key_test.rb
activerecord/test/cases/migration/foreign_key_test.rb
+2
-2
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
b8e1f202
*
Foreign keys added by migrations were given random, generated names. This
meant a different
`structure.sql`
would be generated every time a developer
ran migrations on their machine.
The generated part of foreign key names is now a hash of the table name and
column name, which is consistent every time you run the migration.
*Chris Sinjakli*
*
Validation errors would be raised for parent records when an association
was saved when the parent had
`validate: false`
. It should not be the
responsibility of the model to validate an associated object unless the
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
浏览文件 @
b8e1f202
require
'active_record/migration/join_table'
require
'active_support/core_ext/string/access'
require
'digest'
module
ActiveRecord
module
ConnectionAdapters
# :nodoc:
...
...
@@ -990,8 +992,10 @@ def create_alter_table(name)
end
def
foreign_key_name
(
table_name
,
options
)
# :nodoc:
identifier
=
"
#{
table_name
}
_
#{
options
.
fetch
(
:column
)
}
_fk"
hashed_identifier
=
Digest
::
SHA256
.
hexdigest
(
identifier
).
first
(
10
)
options
.
fetch
(
:name
)
do
"fk_rails_
#{
SecureRandom
.
hex
(
5
)
}
"
"fk_rails_
#{
hashed_identifier
}
"
end
end
...
...
activerecord/test/cases/migration/foreign_key_test.rb
浏览文件 @
b8e1f202
...
...
@@ -57,7 +57,7 @@ def test_add_foreign_key_inferes_column
assert_equal
"rockets"
,
fk
.
to_table
assert_equal
"rocket_id"
,
fk
.
column
assert_equal
"id"
,
fk
.
primary_key
assert_
match
(
/^fk_rails_.{10}$/
,
fk
.
name
)
assert_
equal
(
"fk_rails_78146ddd2e"
,
fk
.
name
)
end
def
test_add_foreign_key_with_column
...
...
@@ -71,7 +71,7 @@ def test_add_foreign_key_with_column
assert_equal
"rockets"
,
fk
.
to_table
assert_equal
"rocket_id"
,
fk
.
column
assert_equal
"id"
,
fk
.
primary_key
assert_
match
(
/^fk_rails_.{10}$/
,
fk
.
name
)
assert_
equal
(
"fk_rails_78146ddd2e"
,
fk
.
name
)
end
def
test_add_foreign_key_with_non_standard_primary_key
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录