]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/old_node.rb
Add inverse_of to relationships that can't detect it automatically
[rails.git] / app / models / old_node.rb
index 81d8e331fcf5e1fc507e5a19119cfc5773e9ab5f..1324c8139bc933bd05589fadc91ba883c8a3270a 100644 (file)
@@ -47,9 +47,9 @@ class OldNode < ApplicationRecord
 
   belongs_to :changeset
   belongs_to :redaction
-  belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
+  belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id", :inverse_of => :old_nodes
 
-  has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version]
+  has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version], :inverse_of => :old_node
 
   def validate_position
     errors.add(:base, "Node is not in the world") unless in_world?
@@ -82,7 +82,7 @@ class OldNode < ApplicationRecord
   end
 
   def tags
-    @tags ||= old_tags.collect { |t| [t.k, t.v] }.to_h
+    @tags ||= old_tags.to_h { |t| [t.k, t.v] }
   end
 
   attr_writer :tags