mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-13 13:21:29 +00:00
Belongs_to has optional true
This commit is contained in:
parent
676c817236
commit
fa7c32c507
40 changed files with 98 additions and 98 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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, -> {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue