I have an array of new objects of active records I want to save them all in one query and I also want to call before_create callback. I used activerecored-import gem and also tried with insert method these both methods skip the callbacks what is best way to do that?
1 Answer
I would suggest that you read the activerecord-import wiki there are lost of interesting facts on how to use that gem there.
here is a key: you have to require 'activerecord-import'
books = []
10.times do |i|
books << Book.new(:name => "book #{i}")
end
Book.import books
this is how you save 10 records with 1 call
Happy coding
1 Comment
Asnad Atta
Thanks for your replay but I want to call my callbacks you can read this github.com/zdennis/activerecord-import/wiki/Callbacks