@tags[k] = v
end
- def save_with_history
- begin
- Way.transaction do
- t = Time.now
- self.timestamp = t
- self.save!
+ def save_with_history!
+ t = Time.now
- tags = self.tags
+ Way.transaction do
+ self.timestamp = t
+ self.save!
+ end
- WayTag.delete_all(['id = ?', self.id])
+ WayTag.transaction do
+ tags = self.tags
- tags.each do |k,v|
- tag = WayTag.new
- tag.k = k
- tag.v = v
- tag.id = self.id
- tag.save!
- end
+ WayTag.delete_all(['id = ?', self.id])
- segs = self.segs
+ tags.each do |k,v|
+ tag = WayTag.new
+ tag.k = k
+ tag.v = v
+ tag.id = self.id
+ tag.save!
+ end
+ end
- WaySegment.delete_all(['id = ?', self.id])
+ WaySegment.transaction do
+ segs = self.segs
- i = 1
- segs.each do |n|
- seg = WaySegment.new
- seg.id = self.id
- seg.segment_id = n
- seg.sequence_id = i
- seg.save!
- i += 1
- end
+ WaySegment.delete_all(['id = ?', self.id])
- old_way = OldWay.from_way(self)
- old_way.timestamp = t
- old_way.save_with_dependencies!
+ i = 1
+ segs.each do |n|
+ seg = WaySegment.new
+ seg.id = self.id
+ seg.segment_id = n
+ seg.sequence_id = i
+ seg.save!
+ i += 1
end
-
- return true
- rescue
- return nil
end
+
+ old_way = OldWay.from_way(self)
+ old_way.timestamp = t
+ old_way.save_with_dependencies!
end
def preconditions_ok?