ruby on rails - Best practise for updating single attribute on multiple records -


i writing exporter within current rails3 project right now. exporter has mark every exported record "exported" (bool). know how in loop, honestly, doesn't feel let rails query database, say, 300 times in row, set 1 field on 300 records.

does know if there's way optimize this? should play manually prepared statements, or rails3 take care of automagically? there sql command in 1 step or something?

thanks help

  • arne

use update_all method on class. rails api:

# update books 'rails' in title book.update_all "author = 'david'", "title '%rails%'" 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -