Module: Amistad::FriendModel

Defined in:
lib/amistad/friend_model.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/amistad/friend_model.rb', line 3

def self.included(receiver)
  receiver.class_exec do
    include InstanceMethods
    
    has_many  :friendships
    
    has_many  :pending_invited,
              :through => :friendships,
              :source => :friend,
              :conditions => { :'friendships.pending' => true, :'friendships.blocked' => false }
              
    has_many  :invited,
              :through => :friendships,
              :source => :friend,
              :conditions => { :'friendships.pending' => false, :'friendships.blocked' => false }

    has_many  :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id"
    
    has_many  :pending_invited_by,
              :through => :inverse_friendships,
              :source => :user,
              :conditions => { :'friendships.pending' => true, :'friendships.blocked' => false }
              
    has_many  :invited_by,
              :through => :inverse_friendships,
              :source => :user,
              :conditions => { :'friendships.pending' => false, :'friendships.blocked' => false }
              
    has_many  :blocked,
              :through => :inverse_friendships,
              :source => :user,
              :conditions => { :'friendships.blocked' => true }
  end
end