-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.rb
105 lines (79 loc) · 1.91 KB
/
models.rb
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
class Position
include Mongoid::Document
include Mongoid::Timestamps
# finding all positions by an office or staffer
index "office.slug"
index "staffer.slug"
# various search form options
index :quarter
index "title.name"
index "office.member.state"
index "office.member.party"
index "office.member.chamber"
index "staffer.first_name"
index "staffer.last_name"
validates_presence_of :quarter
end
class Staffer
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
slug :name
validates_uniqueness_of :slug
index :slug
field :name
field :original_names, :type => Array
field :first_name
field :last_name
index :original_names
index [[:last_name, Mongo::ASCENDING], [:first_name, Mongo::ASCENDING]]
# scope :alphabetical,
end
class Office
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
index :slug
slug :name
validates_uniqueness_of :slug
field :original_names, :type => Array
field :name
field :office_type
field :chamber
index :original_names
index :chamber
index :name
index :office_type
index "committee.id"
index "member.bioguide_id"
scope :members, :where => {:office_type => "member"}
scope :committees, :where => {:office_type => "committee"}
scope :others, :where => {:office_type => "other"}
scope :house, :where => {:chamber => 'house'}
scope :senate, :where => {:chamber => 'senate'}
def member?
office_type == 'member'
end
def committee?
office_type == 'committee'
end
def other?
office_type == 'other'
end
end
class Title
include Mongoid::Document
include Mongoid::Timestamps
field :name
field :original_names, :type => Array
index :name
index :original_names
validates_uniqueness_of :name
end
class Quarter
include Mongoid::Document
include Mongoid::Timestamps
field :name
index :name
validates_uniqueness_of :name
end