]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
Merge remote-tracking branch 'upstream/pull/4796'
[rails.git] / app / models / relation.rb
index 021082eda01243b73f93320e5e0624876c7b73ae..f09647320004f99dc1734964a3e265ffb97b272e 100644 (file)
@@ -27,9 +27,9 @@ class Relation < ApplicationRecord
 
   belongs_to :changeset
 
-  has_many :old_relations, -> { order(:version) }
+  has_many :old_relations, -> { order(:version) }, :inverse_of => :current_relation
 
-  has_many :relation_members, -> { order(:sequence_id) }
+  has_many :relation_members, -> { order(:sequence_id) }, :inverse_of => :relation
   has_many :relation_tags
 
   has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
@@ -166,7 +166,7 @@ class Relation < ApplicationRecord
     # shouldn't be possible to get race conditions.
     Relation.transaction do
       lock!
-      check_consistency(self, new_relation, user)
+      check_update_element_consistency(self, new_relation, user)
       # This will check to see if this relation is used by another relation
       rel = RelationMember.joins(:relation).find_by("visible = ? AND member_type = 'Relation' and member_id = ? ", true, id)
       raise OSM::APIPreconditionFailedError, "The relation #{new_relation.id} is used in relation #{rel.relation.id}." unless rel.nil?
@@ -182,7 +182,7 @@ class Relation < ApplicationRecord
   def update_from(new_relation, user)
     Relation.transaction do
       lock!
-      check_consistency(self, new_relation, user)
+      check_update_element_consistency(self, new_relation, user)
       raise OSM::APIPreconditionFailedError, "Cannot update relation #{id}: data or member data is invalid." unless new_relation.preconditions_ok?(members)
 
       self.changeset_id = new_relation.changeset_id
@@ -195,7 +195,7 @@ class Relation < ApplicationRecord
   end
 
   def create_with_history(user)
-    check_create_consistency(self, user)
+    check_create_element_consistency(self, user)
     raise OSM::APIPreconditionFailedError, "Cannot create relation: data or member data is invalid." unless preconditions_ok?
 
     self.version = 0