浏览 1758 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2007-09-30
db:migration为什么不提供对table外键的直接支持?还要人手工写sql语句,有点太笨了,难道真的像dave Thomas说的,用ror的人从来不在数据库维护constraint?其实我觉得增加约束还是有好处的,毕竟对于数据来说,garbage in , garbage out,在数据库上增加约束是最牢靠的,这不是跟在model上加validator一个道理么?
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2007-09-30
module MigrationHelpers
def foreign_key(from_table, from_column, to_table)
constraint_name="fk_#{from_table}_#{from_column}"
execute "alter table #{from_table}
add constraint #{constraint_name}
foreign key (#{from_column})
references #{to_table}(id)"
end
def remove_foreign_key(table, column)
constraint_name="fk_#{table}_#{column}"
execute "alter table #{table} drop foreign key #{constraint_name}"
end
end
require 'migration_helpers'
class CreateXXX < ActiveRecord::Migration
extend MigrationHelpers
end
或者 http://www.javaeye.com/topic/125789 |
|
| 返回顶楼 | |
|
时间:2007-10-01
可能是考虑到不同数库的支持.
Migration 的数据迁移功能 |
|
| 返回顶楼 | |





