]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
Add inverse_of to relationships that can't detect it automatically
[rails.git] / app / models / relation.rb
index 5ed838e107ea270671c7551d440ad0e014be6aae..61ae45c99d24b65512ce480c55b70ad7dc9a81da 100644 (file)
@@ -22,15 +22,14 @@ class Relation < ApplicationRecord
 
   include ConsistencyValidations
   include NotRedactable
-  include ObjectMetadata
 
   self.table_name = "current_relations"
 
   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
@@ -131,7 +130,7 @@ class Relation < ApplicationRecord
   end
 
   def tags
-    @tags ||= Hash[relation_tags.collect { |t| [t.k, t.v] }]
+    @tags ||= relation_tags.to_h { |t| [t.k, t.v] }
   end
 
   attr_writer :members, :tags
@@ -207,6 +206,8 @@ class Relation < ApplicationRecord
   end
 
   def preconditions_ok?(good_members = [])
+    raise OSM::APITooManyRelationMembersError.new(id, members.length, Settings.max_number_of_relation_members) if members.length > Settings.max_number_of_relation_members
+
     # These are hastables that store an id in the index of all
     # the nodes/way/relations that have already been added.
     # If the member is valid and visible then we add it to the