简体   繁体   中英

Multiple SQL statements for a single array of hash insert

I am doing something like this to insert multiple records at the same time in my rails app.

VoteRecord.create(
  [
    { :prospect_id => prospect.id, :state => "OH", :election_type => "GE" },
    { :prospect_id => prospect.id, :state => "OH", :election_type => "PR" }
    ...
   ]  
)

When I check the log i see that the insert query is fired multiple times by sql. Is it possible to do this in a single query?

您可以尝试使用活动记录导入进行批量导入、签出 wiki 和示例页面。

我自己没有使用过它,但你应该查看 activerecord-import 项目(对于 Rails 3) github更多关于这方面的信息可以在这里找到: wiki

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM