Module: PrivateMessages::Models::PrivateUser::ClassMethods

Defined in:
lib/private_messages/models/private_user.rb

Instance Method Summary collapse

Instance Method Details

#has_private_messages(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/private_messages/models/private_user.rb', line 10

def has_private_messages(options = {})
  class_attribute :options
  klass_name = options[:class_name] ||= "Message"
  table_name = klass_name.constantize.table_name

  has_many :outbox_messages, :class_name => klass_name,
     :foreign_key => 'sender_id', :include => :recipient,
     :order => "#{table_name}.created_at desc"

  has_many :inbox_messages, :class_name => klass_name,
     :foreign_key => 'recipient_id', :include => :sender,
     :order => "#{table_name}.created_at desc"

  unless included_modules.include? InstanceMethods
    include InstanceMethods
  end

  self.options = options
end