Module: Amistad::ActiveRecord::FriendModel

Defined in:
lib/amistad/active_record/friend_model.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



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
37
38
39
40
41
42
43
44
# File 'lib/amistad/active_record/friend_model.rb', line 4

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.blocker_id' => nil }

    has_many  :invited,
    :through => :friendships,
    :source => :friend,
    :conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }

    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.blocker_id' => nil }

    has_many  :invited_by,
    :through => :inverse_friendships,
    :source => :user,
    :conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }

    has_many  :blocked_friendships, :class_name => "Friendship", :foreign_key => "blocker_id"

    has_many  :blockades,
    :through => :blocked_friendships,
    :source => :friend,
    :conditions => "friend_id <> blocker_id"

    has_many  :blockades_by,
    :through => :blocked_friendships,
    :source => :user,
    :conditions => "user_id <> blocker_id"
  end
end