Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class User
  :has_many :domains, :through => :domain_coordinators
  :has_many :regions, :through => :regional_coordinators
  
  :belongs_to :domain
  :belongs_to :region
  
  def domains_responsible_for
    self.domains
  end
  
  def regions_responsible_for
    self.regions # Not very fast code... but will work
  end
  
end

class DomainCoordinator
  :belongs_to :user
  :belongs_to :domain
end

class RegionalCoordinator
  :belongs_to :user
  :belongs_to :region
end


class Domain
  :has_many :coordinators, :through => :domain_coordinators, :source => :users
  :has_many :users

  :belongs_to :region

  def coordinators
    self.coordinators
  end

  def users
    self.users
  end

end

class Region
  :has_many :coordinators, :through => :regional_coordinators, :source => :users
  :has_many :users

  :has_many :domains
  
  def coordinators
    self.coordinators
  end
  
  def users
    self.users
  end
  
end