summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/game.rb2
-rw-r--r--app/models/remote_username.rb6
-rw-r--r--app/models/tournament.rb1
-rw-r--r--app/models/user.rb10
4 files changed, 15 insertions, 4 deletions
diff --git a/app/models/game.rb b/app/models/game.rb
index 345877e..5f4c46d 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -1,3 +1,5 @@
class Game < ActiveRecord::Base
+ belongs_to :parent, class_name: "Game"
+ has_many :children, class_name: "Game"
has_many :settings, class_name: "GameSetting"
end
diff --git a/app/models/remote_username.rb b/app/models/remote_username.rb
index c2c3d20..8c1ce26 100644
--- a/app/models/remote_username.rb
+++ b/app/models/remote_username.rb
@@ -3,7 +3,11 @@ class RemoteUsername < ActiveRecord::Base
belongs_to :user
def value
- JSON.parse(self.json_value)
+ begin
+ return JSON.parse(self.json_value)
+ rescue
+ return {}
+ end
end
def value=(v)
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index e21ccb1..686e066 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -40,6 +40,7 @@ class Tournament < ActiveRecord::Base
end
def []=(setting_name, val)
+ @tournament.save
tournament_setting = @tournament.settings_raw.find_by_name(setting_name)
if tournament_setting.nil?
game_setting = @tournament.game.settings.find_by_name(setting_name)
diff --git a/app/models/user.rb b/app/models/user.rb
index 138f73e..5c0b5b1 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -24,9 +24,13 @@ class User < ActiveRecord::Base
end
def find_remote_username(game)
- obj = remote_username.where(:game => game)
- if obj.nil? and not game.parent.nil?
- return find_remote_username(game.parent)
+ obj = self.remote_usernames.where(:game => game).first
+ if obj.nil?
+ if game.parent.nil?
+ return nil
+ else
+ return find_remote_username(game.parent)
+ end
else
return obj.value
end