With Rails 4.1.1 using the mysql2 adapter:
I use ActiveRecord connectionto do multiple insertion in a MySQL table:
ActiveRecord::Base.connection.execute %Q{
INSERT INTO table (`user_id`, `item_id`)
SELECT 1, id FROM items WHERE items.condition IS NOT NULL
}
This works great, does the job and returns nil.
Is there a way to get the number of rows affected ? (avoiding the need to execute another request)
I found the method documentation executesomewhat rare.
source
share