From: Tom Hughes Date: Fri, 2 Jun 2017 14:55:03 +0000 (+0100) Subject: Remove conditions from delete_all X-Git-Tag: live~4032 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/9b89d4eefe7c3a7df0ca59cabbe85649211f7f95?ds=sidebyside;hp=28d902a1bb9093d161aae99bd7e5c3dc9d05e3e1 Remove conditions from delete_all Passing conditions directory to delete_all is deprecated in rails 5.0 so use a separate where instead. --- diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index a79121b03..540753de5 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -437,7 +437,7 @@ class UserController < ApplicationController if @friend if request.post? if @user.is_friends_with?(@friend) - Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{@friend.id}" + Friend.where(:user_id => @user.id, :friend_user_id => @friend.id).delete_all flash[:notice] = t "user.remove_friend.success", :name => @friend.display_name else flash[:error] = t "user.remove_friend.not_a_friend", :name => @friend.display_name diff --git a/app/controllers/user_roles_controller.rb b/app/controllers/user_roles_controller.rb index 1cfbaf977..9c0339c7a 100644 --- a/app/controllers/user_roles_controller.rb +++ b/app/controllers/user_roles_controller.rb @@ -15,7 +15,7 @@ class UserRolesController < ApplicationController end def revoke - UserRole.delete_all(:user_id => @this_user.id, :role => @role) + UserRole.where(:user_id => @this_user.id, :role => @role).delete_all redirect_to :controller => "user", :action => "view", :display_name => @this_user.display_name end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 549600df6..f41ad9955 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -149,7 +149,7 @@ class Changeset < ActiveRecord::Base save! tags = self.tags - ChangesetTag.delete_all(:changeset_id => id) + ChangesetTag.where(:changeset_id => id).delete_all tags.each do |k, v| tag = ChangesetTag.new diff --git a/app/models/node.rb b/app/models/node.rb index 6346907f1..fb9bdf68b 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -243,7 +243,7 @@ class Node < ActiveRecord::Base # Create a NodeTag tags = self.tags - NodeTag.delete_all(:node_id => id) + NodeTag.where(:node_id => id).delete_all tags.each do |k, v| tag = NodeTag.new tag.node_id = id diff --git a/app/models/relation.rb b/app/models/relation.rb index 899460dbb..d2490dbae 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -317,7 +317,7 @@ class Relation < ActiveRecord::Base # if there are left-over tags then they are new and will have to # be added. tags_changed |= !tags.empty? - RelationTag.delete_all(:relation_id => id) + RelationTag.where(:relation_id => id).delete_all self.tags.each do |k, v| tag = RelationTag.new tag.relation_id = id @@ -347,7 +347,7 @@ class Relation < ActiveRecord::Base # members may be in a different order and i don't feel like implementing # a longest common subsequence algorithm to optimise this. members = self.members - RelationMember.delete_all(:relation_id => id) + RelationMember.where(:relation_id => id).delete_all members.each_with_index do |m, i| mem = RelationMember.new mem.relation_id = id diff --git a/app/models/trace.rb b/app/models/trace.rb index 8179dad22..eed09dbe5 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -261,7 +261,7 @@ class Trace < ActiveRecord::Base first = true # If there are any existing points for this trace then delete them - Tracepoint.delete_all(:gpx_id => id) + Tracepoint.where(:gpx_id => id).delete_all gpx.points do |point| if first diff --git a/app/models/way.rb b/app/models/way.rb index 9877b8bb8..9586094ff 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -271,7 +271,7 @@ class Way < ActiveRecord::Base clone.save! tags = self.tags - WayTag.delete_all(:way_id => id) + WayTag.where(:way_id => id).delete_all tags.each do |k, v| tag = WayTag.new tag.way_id = id @@ -281,7 +281,7 @@ class Way < ActiveRecord::Base end nds = self.nds - WayNode.delete_all(:way_id => id) + WayNode.where(:way_id => id).delete_all sequence = 1 nds.each do |n| nd = WayNode.new