]> git.openstreetmap.org Git - rails.git/blob - app/models/relation_member.rb
82cb4cc8d288669fdb82ceca90febdaf41375b30
[rails.git] / app / models / relation_member.rb
1 class RelationMember < ActiveRecord::Base
2   set_table_name 'current_relation_members'
3   
4   set_primary_keys :id, :sequence_id
5
6   belongs_to :member, :polymorphic => true
7   belongs_to :relation, :foreign_key => :id
8
9   after_find :set_class_from_type
10   after_initialize :set_class_from_type
11   before_save :set_type_from_class
12
13   def member_type=(type)
14     self[:member_type] = type
15     self[:member_class] = type.capitalize
16   end
17
18 private
19
20   def set_class_from_type
21     self[:member_class] = self.member_type.classify unless self.member_type.nil?
22   end
23
24   def set_type_from_class
25     self.member_type = self[:member_class].classify
26   end
27 end