Chr*_*ini 7 migration postgresql activerecord ruby-on-rails ruby-on-rails-4
我有以下迁移:
class CreateFoos < ActiveRecord::Migration
def change
create_table :foos do |t|
t.hstore :foos_properties
end
end
end
Run Code Online (Sandbox Code Playgroud)
在hstore列中,我有2个键::foo和:bar.是否可以创建另一个要删除的迁移:foo?应该怎么样?
我发现了这个:
Foo.update_all([%(foos_properties = delete("foos_properties",?)), 'foo'])
Run Code Online (Sandbox Code Playgroud)
这样安全吗?或者我应该考虑一种更明智的方法?
我认为你的方法很好。我做了一些稍微类似的事情:
ObjectModel.find_each do |object_model|
object_model.foos_properties.delete("foo")
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
985 次 |
| 最近记录: |