]> git.openstreetmap.org Git - rails.git/blob - app/models/relation_member.rb
Yet another at fixing the layout of the search box. Seems to work now
[rails.git] / app / models / relation_member.rb
1 class RelationMember < ActiveRecord::Base
2   set_table_name 'current_relation_members'
3
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!)
13   
14   belongs_to :node, :foreign_key => "member_id"
15   belongs_to :way, :foreign_key => "member_id"
16   belongs_to :relation, :foreign_key => "member_id"
17
18   # so we define this "member" function that returns whatever it
19   # is.
20  
21   def member()
22     return (member_type == "node") ? node : (member_type == "way") ? way : relation
23   end
24
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. 
30 end