【发布时间】:2010-03-09 15:49:58
【问题描述】:
用户可以将数据从文件导入我们的网站。 数据通常包含数百个项目 (Item
虽然验证有帮助,但它们无法解决对内容进行完整性检查的问题。 为此,我们希望有一个测试模式。
我们能否在 Rails/MySQL 中为此使用临时 Items 表,如果可以,我们应该怎么做?
【问题讨论】:
标签: mysql ruby-on-rails activerecord temp-tables
用户可以将数据从文件导入我们的网站。 数据通常包含数百个项目 (Item
虽然验证有帮助,但它们无法解决对内容进行完整性检查的问题。 为此,我们希望有一个测试模式。
我们能否在 Rails/MySQL 中为此使用临时 Items 表,如果可以,我们应该怎么做?
【问题讨论】:
标签: mysql ruby-on-rails activerecord temp-tables
您可以为此使用AR Extensions gem。阅读此article 了解更多详情。
User.create_temporary_table do | temp_model|
# now perform the inserts on temp table.
temp_model.create(...)
...
end # table dropped automatically
或
temp_model = User.create_temporary_table
temp_model.create(...)
#do something
...
...
#drop the temp table
temp_model.drop
【讨论】: