diff --git a/app/models/article.rb b/app/models/article.rb index 9c4f80d..9b2572d 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -61,8 +61,8 @@ class Article < ActiveRecord::Base #scope :nospecial, -> { where("category_id != ?", Category::SPECIAL) } scope :interviews, -> { where(category_id: Category::INTERVIEWS) } - belongs_to :user - belongs_to :category + belongs_to :user, :optional => true + belongs_to :category, :optional => true has_many :comments, as: :commentable, dependent: :destroy has_many :files, class_name: 'DataFile', dependent: :destroy diff --git a/app/models/ban.rb b/app/models/ban.rb index 78a387d..37fa017 100755 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -50,10 +50,10 @@ class Ban < ActiveRecord::Base validates :addr, format: /\A([0-9]{1,3}\.){3}[0-9]{1,3}:?[0-9]{0,5}\z/, allow_blank: true validates :reason, length: {maximum: 255}, allow_blank: true - belongs_to :user - belongs_to :server + belongs_to :user, :optional => true + belongs_to :server, :optional => true - belongs_to :creator, foreign_key: 'creator_id', class_name: 'User' + belongs_to :creator, foreign_key: 'creator_id', class_name: 'User', :optional => true def color expiry.past? ? "green" : "red" diff --git a/app/models/bracket.rb b/app/models/bracket.rb index 9cb8c8f..c5a9fc2 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -19,7 +19,7 @@ class Bracket < ActiveRecord::Base #attr_protected :id, :created_at, :updated_at - belongs_to :contest + belongs_to :contest, :optional => true has_many :bracketers def to_s diff --git a/app/models/bracketer.rb b/app/models/bracketer.rb index 07db263..0449278 100644 --- a/app/models/bracketer.rb +++ b/app/models/bracketer.rb @@ -23,9 +23,9 @@ class Bracketer < ActiveRecord::Base #attr_protected :id, :updated_at, :created_at - belongs_to :contest - belongs_to :match - belongs_to :contester, :foreign_key => "team_id" + belongs_to :contest, :optional => true + belongs_to :match, :optional => true + belongs_to :contester, :foreign_key => "team_id", :optional => true scope :pos, -> (row, col) { where(row: row, column: col) } diff --git a/app/models/challenge.rb b/app/models/challenge.rb index d518c6d..32963a4 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -71,12 +71,12 @@ class Challenge < ActiveRecord::Base has_one :match - belongs_to :map1, :class_name => "Map" - belongs_to :map2, :class_name => "Map" - belongs_to :user - belongs_to :server - belongs_to :contester1, :class_name => "Contester" - belongs_to :contester2, :class_name => "Contester" + belongs_to :map1, :class_name => "Map", :optional => true + belongs_to :map2, :class_name => "Map", :optional => true + belongs_to :user, :optional => true + belongs_to :server, :optional => true + belongs_to :contester1, :class_name => "Contester", :optional => true + belongs_to :contester2, :class_name => "Contester", :optional => true def statuses {STATUS_PENDING => "Pending response", diff --git a/app/models/comment.rb b/app/models/comment.rb index add3cf8..a5555c8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -30,8 +30,8 @@ class Comment < ActiveRecord::Base scope :filtered, -> { where.not({"commentable_type" => 'Issue'}) } scope :ordered, -> { order("id ASC") } - belongs_to :user - belongs_to :commentable, :polymorphic => true + belongs_to :user, :optional => true + belongs_to :commentable, :polymorphic => true, :optional => true validates_presence_of :commentable, :user validates_length_of :text, :in => 1..10000 diff --git a/app/models/contest.rb b/app/models/contest.rb index 513a1ec..e32f59f 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -65,9 +65,9 @@ class Contest < ActiveRecord::Base :source => :predictions, :through => :matches has_and_belongs_to_many :maps - belongs_to :demos, :class_name => "Directory" - belongs_to :winner, :class_name => "Contester" - belongs_to :rules, :class_name => "Article" + belongs_to :demos, :class_name => "Directory", :optional => true + belongs_to :winner, :class_name => "Contester", :optional => true + belongs_to :rules, :class_name => "Article", :optional => true validates_presence_of :name, :start, :end, :status, :default_time validates_length_of :name, :in => 1..50 diff --git a/app/models/contester.rb b/app/models/contester.rb index 6ffc54a..cc2f119 100644 --- a/app/models/contester.rb +++ b/app/models/contester.rb @@ -31,8 +31,8 @@ class Contester < ActiveRecord::Base #attr_protected :id, :updated_at, :created_at, :trend attr_accessor :user - belongs_to :team - belongs_to :contest + belongs_to :team, :optional => true + belongs_to :contest, :optional => true scope :active, -> { includes(:team).where(active: true) } # ranked is used for ladder. lower score the higher the rank diff --git a/app/models/custom_url.rb b/app/models/custom_url.rb index 9bf5081..c6caf31 100644 --- a/app/models/custom_url.rb +++ b/app/models/custom_url.rb @@ -16,7 +16,7 @@ # FIXME: move this to a gem class CustomUrl < ActiveRecord::Base - belongs_to :article + belongs_to :article, :optional => true # FIXME: attr_accessible :name validates :name, diff --git a/app/models/data_file.rb b/app/models/data_file.rb index 8f71a83..ca38c30 100644 --- a/app/models/data_file.rb +++ b/app/models/data_file.rb @@ -45,9 +45,9 @@ class DataFile < ActiveRecord::Base has_one :movie, :foreign_key => :file_id, :dependent => :destroy has_one :preview, :class_name => "Movie", :foreign_key => :preview_id, :dependent => :nullify has_one :match, :foreign_key => :demo_id - belongs_to :directory - belongs_to :related, :class_name => "DataFile" - belongs_to :article + belongs_to :directory, :optional => true + belongs_to :related, :class_name => "DataFile", :optional => true + belongs_to :article, :optional => true validates_length_of [:description, :path], :maximum => 255 diff --git a/app/models/directory.rb b/app/models/directory.rb index 36e562d..926e8eb 100644 --- a/app/models/directory.rb +++ b/app/models/directory.rb @@ -29,7 +29,7 @@ class Directory < ActiveRecord::Base #attr_protected :id, :updated_at, :created_at, :path - belongs_to :parent, :class_name => "Directory" + belongs_to :parent, :class_name => "Directory", :optional => true has_many :subdirs, :class_name => "Directory", :foreign_key => :parent_id has_many :files, -> { order("name") }, :class_name => "DataFile" diff --git a/app/models/forum.rb b/app/models/forum.rb index 32f8700..8eeba69 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -34,7 +34,7 @@ class Forum < ActiveRecord::Base has_many :forumers has_many :groups, :through => :forumers has_one :forumer - belongs_to :category + belongs_to :category, :optional => true after_create :update_position diff --git a/app/models/forumer.rb b/app/models/forumer.rb index dadfa37..b82c4be 100644 --- a/app/models/forumer.rb +++ b/app/models/forumer.rb @@ -28,8 +28,8 @@ class Forumer < ActiveRecord::Base validates_presence_of [:group_id, :forum_id] validates_inclusion_of :access, :in => 0..2 - belongs_to :forum - belongs_to :group + belongs_to :forum, :optional => true + belongs_to :group, :optional => true before_create :init_variables diff --git a/app/models/gather.rb b/app/models/gather.rb index ae7d8ae..4c55596 100644 --- a/app/models/gather.rb +++ b/app/models/gather.rb @@ -42,12 +42,12 @@ class Gather < ActiveRecord::Base scope :active, -> { where("gathers.status IN (?, ?, ?) AND gathers.updated_at > ?", STATE_VOTING, STATE_PICKING, STATE_RUNNING, 12.hours.ago.utc) } - belongs_to :server - belongs_to :captain1, :class_name => "Gatherer" - belongs_to :captain2, :class_name => "Gatherer" - belongs_to :map1, :class_name => "GatherMap" - belongs_to :map2, :class_name => "GatherMap" - belongs_to :category + belongs_to :server, :optional => true + belongs_to :captain1, :class_name => "Gatherer", :optional => true + belongs_to :captain2, :class_name => "Gatherer", :optional => true + belongs_to :map1, :class_name => "GatherMap", :optional => true + belongs_to :map2, :class_name => "GatherMap", :optional => true + belongs_to :category, :optional => true has_many :gatherers has_many :users, :through => :gatherers diff --git a/app/models/gather_map.rb b/app/models/gather_map.rb index d5816be..1723b6e 100644 --- a/app/models/gather_map.rb +++ b/app/models/gather_map.rb @@ -16,8 +16,8 @@ class GatherMap < ActiveRecord::Base scope :ordered, -> { order("votes DESC, id DESC") } - belongs_to :gather - belongs_to :map + belongs_to :gather, :optional => true + belongs_to :map, :optional => true has_many :real_votes, :class_name => "Vote", :as => :votable before_create :init_variables diff --git a/app/models/gather_server.rb b/app/models/gather_server.rb index c7ea73f..4477327 100644 --- a/app/models/gather_server.rb +++ b/app/models/gather_server.rb @@ -13,8 +13,8 @@ class GatherServer < ActiveRecord::Base scope :ordered, -> { order("votes DESC") } - belongs_to :gather - belongs_to :server + belongs_to :gather, :optional => true + belongs_to :server, :optional => true has_many :real_votes, :class_name => "Vote", :as => :votable def to_s diff --git a/app/models/gatherer.rb b/app/models/gatherer.rb index d5bf740..56dbf07 100644 --- a/app/models/gatherer.rb +++ b/app/models/gatherer.rb @@ -63,8 +63,8 @@ class Gatherer < ActiveRecord::Base joins("LEFT JOIN users ON users.id = gatherers.user_id"). where("lastvisit < ?", 30.minutes.ago.utc) } - belongs_to :user - belongs_to :gather + belongs_to :user, :optional => true + belongs_to :gather, :optional => true has_many :real_votes, :class_name => "Vote", :as => :votable, :dependent => :destroy validates_uniqueness_of :user_id, :scope => :gather_id diff --git a/app/models/group.rb b/app/models/group.rb index f260184..af6fcc7 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -33,7 +33,7 @@ class Group < ActiveRecord::Base has_and_belongs_to_many :users has_many :groupers has_many :users, :through => :groupers - belongs_to :founder, :class_name => "User" + belongs_to :founder, :class_name => "User", :optional => true def to_s name diff --git a/app/models/grouper.rb b/app/models/grouper.rb index b181bfa..b53f1de 100644 --- a/app/models/grouper.rb +++ b/app/models/grouper.rb @@ -19,8 +19,8 @@ class Grouper < ActiveRecord::Base #attr_protected :id, :created_at, :updated_at attr_accessor :username - belongs_to :group - belongs_to :user + belongs_to :group, :optional => true + belongs_to :user, :optional => true validates_associated :group, :user validates :group, :user, :presence => true diff --git a/app/models/issue.rb b/app/models/issue.rb index b1e8549..7f67ce7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -37,9 +37,9 @@ class Issue < ActiveRecord::Base #attr_protected :id, :created_at, :updated_at has_many :comments, :as => :commentable - belongs_to :category - belongs_to :author, :class_name => "User" - belongs_to :assigned, :class_name => "User" + belongs_to :category, :optional => true + belongs_to :author, :class_name => "User", :optional => true + belongs_to :assigned, :class_name => "User", :optional => true #scope :unread_by, # lambda { |user| { diff --git a/app/models/lock.rb b/app/models/lock.rb index 064ddc5..821870a 100644 --- a/app/models/lock.rb +++ b/app/models/lock.rb @@ -15,7 +15,7 @@ class Lock < ActiveRecord::Base include Extra - belongs_to :lockable, :polymorphic => true + belongs_to :lockable, :polymorphic => true, :optional => true def can_create? cuser cuser and cuser.admin? diff --git a/app/models/match.rb b/app/models/match.rb index 99f1d56..25e09a2 100755 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -61,20 +61,20 @@ class Match < ActiveRecord::Base has_many :comments, -> { order("created_at") }, :as => :commentable, :dependent => :destroy has_many :match_proposals, inverse_of: :match, dependent: :destroy - belongs_to :challenge - belongs_to :contest - belongs_to :contester1, -> { includes('team') }, :class_name => "Contester" - belongs_to :contester2, -> { includes('team') }, :class_name => "Contester" - belongs_to :map1, :class_name => "Map" - belongs_to :map2, :class_name => "Map" - belongs_to :server - belongs_to :referee, class_name: "User" - belongs_to :motm, class_name: "User" - belongs_to :demo, class_name: "DataFile" - belongs_to :week - belongs_to :hltv, :class_name => "Server" - belongs_to :stream, :class_name => "Movie" - belongs_to :caster, :class_name => "User" + belongs_to :challenge, :optional => true + belongs_to :contest, :optional => true + belongs_to :contester1, -> { includes('team') }, :class_name => "Contester", :optional => true + belongs_to :contester2, -> { includes('team') }, :class_name => "Contester", :optional => true + belongs_to :map1, :class_name => "Map", :optional => true + belongs_to :map2, :class_name => "Map", :optional => true + belongs_to :server, :optional => true + belongs_to :referee, class_name: "User", :optional => true + belongs_to :motm, class_name: "User", :optional => true + belongs_to :demo, class_name: "DataFile", :optional => true + belongs_to :week, :optional => true + belongs_to :hltv, :class_name => "Server", :optional => true + belongs_to :stream, :class_name => "Movie", :optional => true + belongs_to :caster, :class_name => "User", :optional => true scope :future, -> { where("match_time > UTC_TIMESTAMP()") } scope :future5, -> { where("match_time > UTC_TIMESTAMP()").limit(5) } diff --git a/app/models/match_proposal.rb b/app/models/match_proposal.rb index bf42226..f2b5c6f 100644 --- a/app/models/match_proposal.rb +++ b/app/models/match_proposal.rb @@ -23,8 +23,8 @@ class MatchProposal < ActiveRecord::Base # latest time before a match to be confirmed/rejected (in minutes) CONFIRMATION_LIMIT = 30 - belongs_to :match - belongs_to :team + belongs_to :match, :optional => true + belongs_to :team, :optional => true #has_many :confirmed_by, class_name: 'Team', uniq: true # FIXME: attr_accessible :proposed_time, :status diff --git a/app/models/matcher.rb b/app/models/matcher.rb index fb19657..32f0290 100644 --- a/app/models/matcher.rb +++ b/app/models/matcher.rb @@ -22,9 +22,9 @@ class Matcher < ActiveRecord::Base #attr_protected :id, :updated_at, :created_at - belongs_to :match - belongs_to :user - belongs_to :contester + belongs_to :match, :optional => true + belongs_to :user, :optional => true + belongs_to :contester, :optional => true has_many :teams, :through => :contester scope :stats, -> { diff --git a/app/models/message.rb b/app/models/message.rb index bd58efb..4e3b838 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -38,8 +38,8 @@ class Message < ActiveRecord::Base # :joins => "LEFT JOIN readings ON readable_type = 'Message' AND readable_id = messages.id AND readings.user_id = #{user.id}", # :conditions => "readings.user_id IS NULL"} } - belongs_to :sender, :polymorphic => true - belongs_to :recipient, :polymorphic => true + belongs_to :sender, :polymorphic => true, :optional => true + belongs_to :recipient, :polymorphic => true, :optional => true before_save :parse_text after_create :send_notifications diff --git a/app/models/movie.rb b/app/models/movie.rb index d0aa8f1..01bb348 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -50,11 +50,11 @@ class Movie < ActiveRecord::Base .group("movies.id") } scope :active_streams, -> { where("status > 0") } - belongs_to :user - belongs_to :file, :class_name => "DataFile" - belongs_to :preview, :class_name => "DataFile" - belongs_to :match - belongs_to :category + belongs_to :user, :optional => true + belongs_to :file, :class_name => "DataFile", :optional => true + belongs_to :preview, :class_name => "DataFile", :optional => true + belongs_to :match, :optional => true + belongs_to :category, :optional => true has_many :ratings, :as => :rateable has_many :shoutmsgs, :as => :shoutable has_many :watchers diff --git a/app/models/option.rb b/app/models/option.rb index 21caf65..0158ed3 100644 --- a/app/models/option.rb +++ b/app/models/option.rb @@ -22,7 +22,7 @@ class Option < ActiveRecord::Base validates_length_of :option, :in => 1..30 has_many :real_votes, :class_name => "Vote", :as => :votable - belongs_to :poll + belongs_to :poll, :optional => true def to_s self.option diff --git a/app/models/poll.rb b/app/models/poll.rb index 48d0150..89bf602 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -25,7 +25,7 @@ class Poll < ActiveRecord::Base validates_length_of :question, :in => 1..50 #validates_datetime :end_date - belongs_to :user + belongs_to :user, :optional => true has_many :options, :class_name => "Option", :dependent => :destroy has_many :real_votes, :through => :options diff --git a/app/models/post.rb b/app/models/post.rb index bea1d17..b285c05 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -29,8 +29,8 @@ class Post < ActiveRecord::Base before_save :parse_text after_destroy :remove_topics, :if => Proc.new {|post| post.topic.posts.count == 0} - belongs_to :user - belongs_to :topic + belongs_to :user, :optional => true + belongs_to :topic, :optional => true def number pages, i if i != -1 diff --git a/app/models/prediction.rb b/app/models/prediction.rb index 88b29a7..da0e09a 100644 --- a/app/models/prediction.rb +++ b/app/models/prediction.rb @@ -29,8 +29,8 @@ class Prediction < ActiveRecord::Base scope :with_contest, -> { includes({:match => :contest}) } - belongs_to :match - belongs_to :user + belongs_to :match, :optional => true + belongs_to :user, :optional => true def can_create? cuser cuser and match.match_time.future? and !match.score1 and !match.score2 and !cuser.predictions.exists?(:match_id => match.id) diff --git a/app/models/profile.rb b/app/models/profile.rb index dea5252..905dc91 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -65,7 +65,7 @@ class Profile < ActiveRecord::Base #attr_protected :user_id, :id, :updated_at, :created_at - belongs_to :user + belongs_to :user, :optional => true validates_length_of :msn, :maximum => 50 validates_format_of :msn, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :allow_blank => true diff --git a/app/models/server.rb b/app/models/server.rb index 24d18e2..2642787 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -74,8 +74,8 @@ class Server < ActiveRecord::Base has_many :logs has_many :matches has_many :challenges - belongs_to :user - belongs_to :recordable, :polymorphic => true + belongs_to :user, :optional => true + belongs_to :recordable, :polymorphic => true, :optional => true before_create :set_category diff --git a/app/models/shoutmsg.rb b/app/models/shoutmsg.rb index a7bc712..0fd3349 100644 --- a/app/models/shoutmsg.rb +++ b/app/models/shoutmsg.rb @@ -24,8 +24,8 @@ class Shoutmsg < ActiveRecord::Base validates_length_of :text, :in => 1..100 validates_presence_of :user - belongs_to :user - belongs_to :shoutable, :polymorphic => true + belongs_to :user, :optional => true + belongs_to :shoutable, :polymorphic => true, :optional => true scope :recent, -> { includes(:user).order("id DESC").limit(8) } diff --git a/app/models/team.rb b/app/models/team.rb index 838b0fa..9d027a6 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -50,7 +50,7 @@ class Team < ActiveRecord::Base scope :ordered, -> { order("name") } scope :recruiting, -> { where("recruiting IS NOT NULL AND recruiting != ''") } - belongs_to :founder, :class_name => "User" + belongs_to :founder, :class_name => "User", :optional => true has_many :active_teamers, -> { where("rank >= ?", Teamer::RANK_MEMBER) } has_many :teamers, :dependent => :destroy, :counter_cache => true diff --git a/app/models/teamer.rb b/app/models/teamer.rb index 011fe78..57fcdc9 100644 --- a/app/models/teamer.rb +++ b/app/models/teamer.rb @@ -48,8 +48,8 @@ class Teamer < ActiveRecord::Base where("user_id = ? AND created_at < ? AND ((updated_at > ? AND rank = ?) OR rank >= ?)", user.id, time.utc, time.utc, RANK_REMOVED, RANK_MEMBER) } - belongs_to :user - belongs_to :team + belongs_to :user, :optional => true + belongs_to :team, :optional => true has_many :other_teamers, -> { where("teamers.id != ?", object_id) }, :through => :user, :source => :teamers has_many :contesters, :through => :team diff --git a/app/models/topic.rb b/app/models/topic.rb index 8a28927..a3bee10 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -28,8 +28,8 @@ class Topic < ActiveRecord::Base #attr_protected :id, :updated_at, :created_at attr_accessor :first_post - belongs_to :user - belongs_to :forum + belongs_to :user, :optional => true + belongs_to :forum, :optional => true has_one :lock, :as => :lockable has_one :latest, -> { order("id DESC") }, :class_name => "Post" has_many :posts, -> { order("id ASC") }, :dependent => :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 5245ec5..8049649 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,7 +48,7 @@ class User < ActiveRecord::Base attribute :lastvisit, :datetime, default: Time.now.utc - belongs_to :team, :optional => true + belongs_to :team, :optional => true, :optional => true has_one :profile, :dependent => :destroy has_many :bans, :dependent => :destroy has_many :articles, :dependent => :destroy diff --git a/app/models/view_count.rb b/app/models/view_count.rb index fa9201a..a16b487 100644 --- a/app/models/view_count.rb +++ b/app/models/view_count.rb @@ -15,6 +15,6 @@ # class ViewCount < ActiveRecord::Base - belongs_to :viewable, :polymorphic => true + belongs_to :viewable, :polymorphic => true, :optional => true validates_uniqueness_of :ip_address, :scope => [ :viewable_id, :viewable_type ] end diff --git a/app/models/vote.rb b/app/models/vote.rb index 2d60c60..1bd0de3 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -22,8 +22,8 @@ class Vote < ActiveRecord::Base validates_uniqueness_of :user_id, :scope => :votable_id validates_presence_of :user_id, :votable_id, :votable_type - belongs_to :user - belongs_to :votable, :polymorphic => true + belongs_to :user, :optional => true + belongs_to :votable, :polymorphic => true, :optional => true after_create :increase_votes after_destroy :decrease_votes diff --git a/app/models/week.rb b/app/models/week.rb index d58d843..3536aa0 100644 --- a/app/models/week.rb +++ b/app/models/week.rb @@ -28,9 +28,9 @@ class Week < ActiveRecord::Base scope :ordered, -> { order("start_date ASC") } - belongs_to :contest - belongs_to :map1, :class_name => "Map" - belongs_to :map2, :class_name => "Map" + belongs_to :contest, :optional => true + belongs_to :map1, :class_name => "Map", :optional => true + belongs_to :map2, :class_name => "Map", :optional => true has_many :matches def to_s