Skip to content

Commit

Permalink
Fix error resolving relation parents
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tomhughes committed Jul 23, 2014
1 parent 0b9bf8d commit c729406
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/relation_member.rb
Expand Up @@ -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
27 changes: 27 additions & 0 deletions test/models/node_test.rb
Expand Up @@ -331,4 +331,31 @@ def test_tags
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
17 changes: 17 additions & 0 deletions test/models/relation_test.rb
Expand Up @@ -144,4 +144,21 @@ def test_tags
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
17 changes: 17 additions & 0 deletions test/models/way_test.rb
Expand Up @@ -180,4 +180,21 @@ def test_tags
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

0 comments on commit c729406

Please sign in to comment.