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
23
24
# 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 => item.author_type, :author_id => item.author_id) }
    scope :with_email, lambda { |email| where(:user_email => email) }
    scope :with_phone, lambda { |phone| where(:phone_number => phone) }
  end
end

Instance Method Details

#siblings_for(record) ⇒ Object



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

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