]> git.openstreetmap.org Git - rails.git/blob - app/models/old_way.rb
way stuff, now creates correctly
[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     save()
18     self.reload()
19
20     self.tags.each do |k,v|
21       tag = OldWayTag.new
22       tag.k = k
23       tag.v = v
24       tag.id = self.id
25       tag.version = self.version
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.version = self.version
35       seg.save
36     end
37   end
38
39   def segs
40     @segs = Array.new unless @segs
41     @segs
42   end
43
44   def tags
45     @tags = Hash.new unless @tags
46     @tags
47   end
48
49   def segs=(s)
50     @segs = s
51   end
52
53   def tags=(t)
54     @tags = t
55   end
56
57 end