From b72fedb162d3fcecc304d7dfe5f67acb30844099 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 22 Jun 2008 14:44:34 +0000 Subject: [PATCH] Make the polymorphic relation association work properly. --- app/models/node.rb | 10 +++++----- app/models/old_node.rb | 4 +++- app/models/relation.rb | 4 ++-- app/models/tracepoint.rb | 4 +++- {app/models => lib}/geo_record.rb | 6 ++++-- 5 files changed, 17 insertions(+), 11 deletions(-) rename {app/models => lib}/geo_record.rb (94%) diff --git a/app/models/node.rb b/app/models/node.rb index 4393f2526..be444bf3e 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -1,8 +1,8 @@ -# The node model represents a current existing node, that is, the latest version. Use OldNode for historical nodes. - -class Node < GeoRecord +class Node < ActiveRecord::Base require 'xml/libxml' + include GeoRecord + set_table_name 'current_nodes' validates_presence_of :user_id, :timestamp @@ -17,8 +17,8 @@ class Node < GeoRecord has_many :way_nodes has_many :ways, :through => :way_nodes - has_many :containing_relation_members, :as => :member - has_many :containing_relations, :through => :containing_relation_members + has_many :containing_relation_members, :class_name => "RelationMember", :as => :member + has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation # Sanity check the latitude and longitude and add an error if it's broken def validate_position diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 2c3e93b20..891b89731 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -1,4 +1,6 @@ -class OldNode < GeoRecord +class OldNode < ActiveRecord::Base + include GeoRecord + set_table_name 'nodes' validates_presence_of :user_id, :timestamp diff --git a/app/models/relation.rb b/app/models/relation.rb index cd2d67cdd..71ddc4a55 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -10,8 +10,8 @@ class Relation < ActiveRecord::Base has_many :relation_members, :foreign_key => 'id' has_many :relation_tags, :foreign_key => 'id' - has_many :containing_relation_members, :as => :member - has_many :containing_relations, :through => :containing_relation_members + has_many :containing_relation_members, :class_name => "RelationMember", :as => :member + has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation def self.from_xml(xml, create=false) begin diff --git a/app/models/tracepoint.rb b/app/models/tracepoint.rb index 8648e555d..bf3cdd7c0 100644 --- a/app/models/tracepoint.rb +++ b/app/models/tracepoint.rb @@ -1,4 +1,6 @@ -class Tracepoint < GeoRecord +class Tracepoint < ActiveRecord::Base + include GeoRecord + set_table_name 'gps_points' validates_numericality_of :trackid, :only_integer => true diff --git a/app/models/geo_record.rb b/lib/geo_record.rb similarity index 94% rename from app/models/geo_record.rb rename to lib/geo_record.rb index ddd029aec..d5604d4d3 100644 --- a/app/models/geo_record.rb +++ b/lib/geo_record.rb @@ -1,5 +1,7 @@ -class GeoRecord < ActiveRecord::Base - before_save :update_tile +module GeoRecord + def before_save + self.update_tile + end # Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180 # * returns true/false -- 2.43.2