]> git.openstreetmap.org Git - rails.git/blob - app/models/old_way.rb
more way bits
[rails.git] / app / models / old_way.rb
1 class OldWay < ActiveRecord::Base
2   set_table_name 'ways'
3
4   belongs_to :user
5
6   def self.from_way(way)
7     old_way = OldWay.new
8     old_way.user_id = way.user_id
9     old_way.timestamp = way.timestamp
10     old_way.id = way.id
11     old_way.segs = way.segs
12     old_way.tags = way.tags
13     return old_way
14   end
15
16   def save_with_dependencies
17     t = Time.now
18     self.timestamp = t
19     self.save
20     
21     self.tags.each do |k,v|
22       tag = OldWayTag.new
23       tag.k = k
24       tag.v = v
25       tag.id = self.id
26       tag.save
27     end
28
29     i = 0
30     self.segs.each do |n|
31       seg = OldWaySegment.new
32       seg.id = self.id
33       seg.segment_id = n
34       seg.sequence_id = i
35       seg.save
36       i += 1
37     end
38
39     old_way = OldWay.from_way(self)
40     old_way.save
41   end
42
43   def segs
44     @segs = Array.new unless @segs
45     @segs
46   end
47
48   def tags
49     @tags = Hash.new unless @tags
50     @tags
51   end
52
53   def segs=(s)
54     @segs = s
55   end
56
57   def tags=(t)
58     @tags = t
59   end
60
61 end