1 class RelationMember < ActiveRecord::Base
2 set_table_name 'current_relation_members'
4 # problem with RelationMember is that it may link to any one
5 # object (a node, a way, another relation), and belongs_to is
6 # not flexible enough for that. So we do this, which is ugly,
7 # but fortunately rails won't actually run the SQL behind that
8 # unless someone really accesses .node, .way, or
9 # .relation - which is what we do below based on member_type.
10 # (and no: the :condition on belongs_to doesn't work here as
11 # it is a condition on the *referenced* object not the
12 # *referencing* object!)
14 belongs_to :node, :foreign_key => "member_id"
15 belongs_to :way, :foreign_key => "member_id"
16 belongs_to :relation, :foreign_key => "member_id"
18 # so we define this "member" function that returns whatever it
22 return (member_type == "node") ? node : (member_type == "way") ? way : relation
25 # NOTE - relations are SUBJECTS of memberships. The fact that nodes,
26 # ways, and relations can be the OBJECT of a membership,
27 # i.e. a node/way/relation can be referenced throgh a
28 # RelationMember object, is NOT modelled in rails, i.e. these links
29 # have to be resolved manually, on demand.