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?
Asked
Active
Viewed 1,711 times
-4
-
Could you please write any code sample here. – Dinesh Saini Apr 22 '15 at 06:57
-
Have a read of http://stackoverflow.com/q/2509320/385532 – Matt Apr 22 '15 at 08:57
1 Answers
1
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

MZaragoza
- 10,108
- 9
- 71
- 116
-
Thanks for your replay but I want to call my callbacks you can read this https://github.com/zdennis/activerecord-import/wiki/Callbacks – Asnad Atta May 13 '15 at 06:31