ActiveRecord’s update_all/delete_all
methods is efficient, because it don’t need to instantiate object. But it only renurn number of changed rows at present, and sometimes I need to return some specific data, eg: id.
At this time, I can only execute the query statement once. Unfortunately, I cannot ensure that the query result is latest. Because after the query, there may be new data changes. This is terrible.
Alternatives. I can use exec_query
method to execute sql for my purpose, but it is not elegant.
I hope update_all/delete_all
can return specific data. eg:
User.returning(:id).delete_all === User.connection.exec_query('DELETE FROM "users" RETURNING "users"."id"')
PS: English is not my native language; please excuse typing errors.