]> git.openstreetmap.org Git - rails.git/commitdiff
Fix error resolving relation parents
authorTom Hughes <tom@compton.nu>
Wed, 23 Jul 2014 23:23:45 +0000 (00:23 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 23 Jul 2014 23:23:45 +0000 (00:23 +0100)
It's not entirely clear why specifying the foreign key explicitly
fixes this - the value given is what it should default to - but
without this it finds the child relation instead when looking at
the parents of a relation.

Fixes #789

app/models/relation_member.rb
test/models/node_test.rb
test/models/relation_test.rb
test/models/way_test.rb

index aba38511ce5e01399bb702a9ef3115b295cd95fa..e5c783f5c68b788e7d5f034970a3a4ebc28acd5e 100644 (file)
@@ -2,6 +2,6 @@ class RelationMember < ActiveRecord::Base
   self.table_name = "current_relation_members"
   self.primary_keys = "relation_id", "sequence_id"
 
-  belongs_to :relation
+  belongs_to :relation, :foreign_key => :relation_id
   belongs_to :member, :polymorphic => true
 end
index 9ad968ae91fd0abe9164c191b18f5382c660f729..7acc6168f73a518f499a147793a5d256aab3cfee 100644 (file)
@@ -331,4 +331,31 @@ class NodeTest < ActiveSupport::TestCase
     assert_equal "added in node version 3", tags["testing"]
     assert_equal "modified in node version 4", tags["testing two"]
   end
+
+  def test_containing_relation_members
+    node = current_nodes(:node_used_by_relationship)
+    crm = Node.find(node.id).containing_relation_members.order(:relation_id)
+#    assert_equal 3, crm.size
+    assert_equal 1, crm.first.relation_id
+    assert_equal "Node", crm.first.member_type
+    assert_equal node.id, crm.first.member_id
+    assert_equal 1, crm.first.relation.id
+    assert_equal 2, crm.second.relation_id
+    assert_equal "Node", crm.second.member_type
+    assert_equal node.id, crm.second.member_id
+    assert_equal 2, crm.second.relation.id
+    assert_equal 3, crm.third.relation_id
+    assert_equal "Node", crm.third.member_type
+    assert_equal node.id, crm.third.member_id
+    assert_equal 3, crm.third.relation.id
+  end
+
+  def test_containing_relations
+    node = current_nodes(:node_used_by_relationship)
+    cr = Node.find(node.id).containing_relations.order(:id)
+    assert_equal 3, cr.size
+    assert_equal 1, cr.first.id
+    assert_equal 2, cr.second.id
+    assert_equal 3, cr.third.id
+  end
 end
index 7141f54f0c62701ee1c52218195271dab725992e..5d60ebb52c853813c9a7ee0c8a6e960fd9bed5c8 100644 (file)
@@ -144,4 +144,21 @@ class RelationTest < ActiveSupport::TestCase
     assert_equal "added in relation version 3", tags["testing"]
     assert_equal "modified in relation version 4", tags["testing two"]
   end
+
+  def test_containing_relation_members
+    relation = current_relations(:used_relation)
+    crm = Relation.find(relation.id).containing_relation_members.order(:relation_id)
+#    assert_equal 1, crm.size
+    assert_equal 1, crm.first.relation_id
+    assert_equal "Relation", crm.first.member_type
+    assert_equal relation.id, crm.first.member_id
+    assert_equal 1, crm.first.relation.id
+  end
+
+  def test_containing_relations
+    relation = current_relations(:used_relation)
+    cr = Relation.find(relation.id).containing_relations.order(:id)
+    assert_equal 1, cr.size
+    assert_equal 1, cr.first.id
+  end
 end
index eb5baef10c32d0b623bb450543be535bd4725583..de0eb61466964a8ab0a93e421bad6dc2579129a1 100644 (file)
@@ -180,4 +180,21 @@ class WayTest < ActiveSupport::TestCase
     assert_equal "added in way version 3", tags["testing"]
     assert_equal "modified in way version 4", tags["testing two"]
   end
+
+  def test_containing_relation_members
+    way = current_ways(:used_way)
+    crm = Way.find(way.id).containing_relation_members.order(:relation_id)
+#    assert_equal 1, crm.size
+    assert_equal 1, crm.first.relation_id
+    assert_equal "Way", crm.first.member_type
+    assert_equal way.id, crm.first.member_id
+    assert_equal 1, crm.first.relation.id
+  end
+
+  def test_containing_relations
+    way = current_ways(:used_way)
+    cr = Way.find(way.id).containing_relations.order(:id)
+    assert_equal 1, cr.size
+    assert_equal 1, cr.first.id
+  end
 end