2014-10-28 06:36:38 +01:00
|
|
|
class Question < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
2014-12-28 21:42:21 +01:00
|
|
|
has_many :answers, dependent: :destroy
|
2014-12-28 00:34:56 +01:00
|
|
|
has_many :inboxes, dependent: :destroy
|
2014-12-08 15:34:37 +01:00
|
|
|
|
2014-12-08 23:02:31 +01:00
|
|
|
validates :content, length: { maximum: 255 }
|
2014-12-14 12:03:57 +01:00
|
|
|
|
2014-12-28 21:58:11 +01:00
|
|
|
before_destroy do
|
|
|
|
user.decrement! :asked_count unless self.author_is_anonymous
|
|
|
|
end
|
|
|
|
|
2014-12-14 12:19:52 +01:00
|
|
|
def can_be_removed?
|
|
|
|
return false if self.answers.count > 0
|
|
|
|
return false if Inbox.where(question: self).count > 1
|
|
|
|
true
|
2014-12-14 12:03:57 +01:00
|
|
|
end
|
2014-10-28 06:36:38 +01:00
|
|
|
end
|