X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/2af0840ff314f9d1e0265a4a1b50fc6db4af9047..4e64291839d45a0c660fc84f11a6c4c811cf8f21:/app/models/relation.rb?ds=sidebyside diff --git a/app/models/relation.rb b/app/models/relation.rb index 3d3c317aa..cb9621822 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -246,8 +246,10 @@ class Relation < ActiveRecord::Base # use reflection to look up the appropriate class model = Kernel.const_get(m[0].capitalize) - # get the element with that ID - element = model.find_by(:id => m[1]) + # get the element with that ID. and, if found, lock the element to + # ensure it can't be deleted until after the current transaction + # commits. + element = model.lock("for share").find_by(:id => m[1]) # and check that it is OK to use. unless element && element.visible? && element.preconditions_ok?