3
3
4
4
#Rename to Team when Mongodb is dropped
5
5
class Team < ActiveRecord ::Base
6
+ DEFAULT_HEX_BRAND = '#343131'
7
+ LEADERBOARD_KEY = 'teams:leaderboard'
8
+ FEATURED_TEAMS_CACHE_KEY = 'featured_teams_results'
9
+ MAX_TEAM_SCORE = 400
10
+
11
+ self . table_name = 'teams'
12
+
6
13
include SearchModule
7
14
include TeamSearch
15
+ include LeaderboardRedisRank
16
+ include TeamAnalytics
17
+ include TeamMigration
18
+
19
+ mount_uploader :avatar , TeamUploader
20
+
8
21
mapping team : {
9
22
properties : {
10
23
id : { type : 'string' , index : 'not_analyzed' } ,
@@ -27,35 +40,33 @@ class Team < ActiveRecord::Base
27
40
}
28
41
}
29
42
30
- include LeaderboardRedisRank
31
- include TeamAnalytics
32
- include TeamMigration
43
+ scope :featured , -> { where ( premium : true , valid_jobs : true , hide_from_featured : false ) }
33
44
34
- DEFAULT_HEX_BRAND = '#343131'
35
- LEADERBOARD_KEY = 'teams:leaderboard'
36
- FEATURED_TEAMS_CACHE_KEY = 'featured_teams_results'
37
- MAX_TEAM_SCORE = 400
38
45
39
- self . table_name = 'teams'
46
+ before_validation :create_slug!
47
+
48
+ validates :slug , uniqueness : true , presence : true
49
+
40
50
41
- #TODO add inverse_of
42
- has_one :account , class_name : 'Teams::Account' , foreign_key : 'team_id' , dependent : :delete
51
+ has_many :followers , through : :follows , source : :team
43
52
44
- has_many :members , class_name : 'Teams::Member' , foreign_key : 'team_id' , dependent : :delete_all
45
- has_many :links , class_name : 'Teams::Link' , foreign_key : 'team_id' , dependent : :delete_all
53
+ has_many :follows , class_name : 'FollowedTeam' , foreign_key : 'team_id' , dependent : :destroy
54
+ has_many :jobs , class_name : 'Opportunity' , foreign_key : 'team_id' , dependent : :destroy
55
+ has_many :links , class_name : 'Teams::Link' , foreign_key : 'team_id' , dependent : :delete_all
46
56
has_many :locations , class_name : 'Teams::Location' , foreign_key : 'team_id' , dependent : :delete_all
57
+ has_many :members , class_name : 'Teams::Member' , foreign_key : 'team_id' , dependent : :delete_all
58
+ has_one :account , class_name : 'Teams::Account' , foreign_key : 'team_id' , dependent : :delete
47
59
48
60
def featured_links
49
61
links
50
62
end
51
63
52
64
has_many :jobs , class_name : 'Opportunity' , foreign_key : 'team_id' , dependent : :destroy
53
65
54
- # def jobs
55
- #all_jobs.valid
56
- # end
66
+ private def create_slug!
67
+ self . slug = name . parameterize
68
+ end
57
69
58
- #Replaced with jobs
59
70
def all_jobs
60
71
jobs . order ( 'created_at DESC' )
61
72
end
@@ -186,10 +197,6 @@ def university?
186
197
true
187
198
end
188
199
189
- def locations
190
- ( location || '' ) . split ( ';' ) . collect { |location | location . strip }
191
- end
192
-
193
200
def locations_message
194
201
if premium?
195
202
locations . collect ( &:name ) . join ( ', ' )
0 commit comments