Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Insert many records, commit once


  • Please log in to reply
2 replies to this topic

#1 santi_2010

santi_2010

    Passenger

  • Members
  • 7 posts

Posted 09 November 2013 - 07:23 PM

Hi everyone!

 

 After uploading a file, I parse it and then I save those records in the database as it shown here:

sheet1.each 1 do |row|
  @time_record = TimeRecord.create(:employee_id => 2 , :date => DateTime.parse(row[3]))
  @time_record.save
end

The problem is that in this way I am doing a commit after every insert

How can I insert everything and then commit?

 

Thanks for your answers!

 



#2 Jamie

Jamie

    Controller

  • Moderators
  • 114 posts
  • LocationThe UK

Posted 09 November 2013 - 10:04 PM   Best Answer

Hello

 

You might want to check out https://github.com/z...ord-import/wiki if you're using AR.


Rails developer based in Newcastle, UK.
Web app owner - Twitter lover

#3 santi_2010

santi_2010

    Passenger

  • Members
  • 7 posts

Posted 10 November 2013 - 04:20 PM

Great gem! Simple and fast, just amazing!

 

Thanks Jamie!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users