mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-02-04 15:31:09 +00:00
Fix #131 Updating users may fail
Issue: When a team gets deleted team_id is not properly cleared from users who have set the team to be deleted as their main. When now someone trys an operation that validates the user it fails as the team_id set on that user is not valid anymore. Solution: To prevent this from happening in the future update users and set team_id to nil. Clean up: To clean up existing users run UPDATE users SET team_id=NULL WHERE team_id NOT IN(SELECT id FROM teams);
This commit is contained in:
parent
91a8cdca59
commit
e93588591b
2 changed files with 4 additions and 1 deletions
|
@ -93,6 +93,9 @@ class Team < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def destroy
|
||||
User.where(team_id: self.id).each do |user|
|
||||
user.update_attribute(:team_id, nil)
|
||||
end
|
||||
if matches.count > 0
|
||||
update_attribute :active, false
|
||||
teamers.update_all ["rank = ?", Teamer::RANK_REMOVED]
|
||||
|
|
|
@ -50,7 +50,7 @@ class Teamer < ActiveRecord::Base
|
|||
scope :distinct,
|
||||
:group => "user_id, team_id"
|
||||
scope :ordered,
|
||||
:order => "rank DESC, created_at ASC"
|
||||
:order => "`rank` DESC, `created_at` ASC"
|
||||
scope :historic,
|
||||
lambda { |user, time|
|
||||
{:conditions => ["user_id = ? AND created_at < ? AND ((updated_at > ? AND rank = ?) OR rank >= ?)",
|
||||
|
|
Loading…
Reference in a new issue