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
|
# File 'lib/rails_friends/friendable.rb', line 7
def has_friendship
class_eval do
has_many :friendships, as: :friendable,
class_name: 'RailsFriends::Friendship', dependent: :destroy
has_many :blocked_friends,
-> { where friendships: { status: 3 } },
through: :friendships,
source: :friend
has_many :friends,
-> { where friendships: { status: 2 } },
through: :friendships
has_many :requested_friends,
-> { where friendships: { status: 1 } },
through: :friendships,
source: :friend
has_many :pending_friends,
-> { where friendships: { status: 0 } },
through: :friendships,
source: :friend
def self.friendable?
true
end
end
include RailsFriends::Friendable::InstanceMethods
include RailsFriends::Extender
end
|