Guest User

Untitled

a guest
Nov 22nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. ActiveRecord::Base.transaction do
  2. new_ids =
  3. ActiveRecord::Base.connection.execute(
  4. params[:sql]).column_values(0)
  5. #get ids - 0th column in result-table
  6. same_ids = (new_ids.sort == (params[:ids].to_a.collect{|id|
  7. id.to_i}).sort)
  8.  
  9. if !same_ids
  10. result = ActiveRecord::Base.connection.execute(params[:sql])
  11. model = params[:model].camelize.classify.constantize
  12. fields = result.fields
  13.  
  14. recordset = model.where(id: new_ids).order_as_specified(id: new_ids)
  15. ...
  16. end
  17. raise ActiveRecord::Rollback #sql must be run inside transaction for security
  18. end
  19. if !same_ids
  20. ... (Handle the change)
Add Comment
Please, Sign In to add comment