Is there a way in Rails to insert many records at once, with a single SQL command? I've noticed that loading a dump file of data from the command line is much faster to doing something like SomeModelClass.create(...) for each individual record. --Paul
create accepts an array of hashes as well as a single hash.
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001379
Is there a way in Rails to insert many records at once, with a single SQL command? I've noticed that loading a dump file of data from the command line is much faster to doing something like SomeModelClass.create(...) for each individual record.
create accepts an array of hashes as well as a single hash.
Which won't make any speed difference since if you pass it an array of
hashes it just iterates over that array calling create on each element.
In times like these I've occasionally fallen back to just creating an
sql statement to insert all the values and executing it. You lose AR
type conveniences(validations etc...) but it is a lot faster on large
numbers of records.
Fred