]> git.openstreetmap.org Git - rails.git/commitdiff
Make the polymorphic relation association work properly.
authorTom Hughes <tom@compton.nu>
Sun, 22 Jun 2008 14:44:34 +0000 (14:44 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 22 Jun 2008 14:44:34 +0000 (14:44 +0000)
app/models/node.rb
app/models/old_node.rb
app/models/relation.rb
app/models/tracepoint.rb
lib/geo_record.rb [moved from app/models/geo_record.rb with 94% similarity]

index 4393f252679e12cf7a6c606ecd1331ad938228a2..be444bf3e252fee4832ea12e8c31dfa4124d9742 100644 (file)
@@ -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
index 2c3e93b2075fc5de263923694f50221123734ec1..891b89731ec2062071b06f5605e7442ec971b3f2 100644 (file)
@@ -1,4 +1,6 @@
-class OldNode < GeoRecord
+class OldNode < ActiveRecord::Base
+  include GeoRecord
+
   set_table_name 'nodes'
   
   validates_presence_of :user_id, :timestamp
index cd2d67cdde0b969020d88530fdc82748f6f19451..71ddc4a554f0e696b83187d1df5014bade7946c3 100644 (file)
@@ -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
index 8648e555d2ec4c62fd9332fc6fd3bfbb6e9530e2..bf3cdd7c06557978e40614360394b22e85ba78db 100644 (file)
@@ -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
similarity index 94%
rename from app/models/geo_record.rb
rename to lib/geo_record.rb
index ddd029aec0f3db85b1b447928994eab5ac2824cc..d5604d4d36db5882aafd2cff00d25816294dcb16 100644 (file)
@@ -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