Module: Sunrise::Models::FeedbackMessage::ClassMethods

Defined in:
lib/sunrise/models/feedback_message.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sunrise/models/feedback_message.rb', line 11

def self.extended(base)
  base.class_eval do
    has_many :answers, :class_name => 'FeedbackAnswer', :foreign_key => :message_id, :dependent => :delete_all
    belongs_to :author, :polymorphic => true
    
    before_validation :make_author
    
    default_scope order("#{quoted_table_name}.id DESC")
    scope :recently, order("#{quoted_table_name}.created_at DESC")
    scope :with_author, lambda { |item| where(["author_type = ? AND author_id = ?", item.author_type, item.author_id]) }
  end
end

Instance Method Details

#siblings_for(record) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/sunrise/models/feedback_message.rb', line 24

def siblings_for(record)
  query = scoped
  
  Sunrise::Feedbacks.siblings_keys.each do |key|
    query = query.where(["#{key} = ?", record.send(key)])
  end
  
  query
end