Skip to content

Commit c16c395

Browse files
committed
fix models
1 parent 8496a84 commit c16c395

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

app/models/invitation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
#
1515

1616
class Invitation < ActiveRecord::Base
17+
belongs_to :team
18+
belongs_to :user, foreign_key: :inviter_id
1719
end

app/models/opportunity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Opportunity < ActiveRecord::Base
3737

3838
OPPORTUNITY_TYPES = %w(full-time part-time contract internship)
3939

40-
has_many :seized_opportunities
40+
has_many :seized_opportunities, :delete_all
4141

4242
# Order here dictates the order of validation error messages displayed in views.
4343
validates :name, presence: true, allow_blank: false

app/models/team.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class Team < ActiveRecord::Base
9090

9191
mount_uploader :avatar, TeamUploader
9292

93+
has_many :invitations, dependent: :delete_all
94+
has_many :opportunities, dependent: :destroy
9395
has_many :followers, through: :follows, source: :team
9496
has_many :follows, class_name: 'FollowedTeam', foreign_key: 'team_id', dependent: :destroy
9597
has_many :jobs, class_name: 'Opportunity', foreign_key: 'team_id', dependent: :destroy
@@ -739,10 +741,9 @@ def reindex_search
739741
end
740742
end
741743

744+
742745
def remove_dependencies
743-
[FollowedTeam, Invitation, Opportunity, SeizedOpportunity].each do |klass|
744-
klass.where(team_id: self.id.to_s).delete_all
745-
end
746+
FollowedTeam.where(team_id: self.id.to_s).delete_all
746747
User.where(team_id: self.id.to_s).update_all('team_id = NULL')
747748
end
748749

0 commit comments

Comments
 (0)