Module: Diaspora::Likeable

Included in:
Comment, Post
Defined in:
lib/diaspora/likeable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object


7
8
9
10
11
12
# File 'lib/diaspora/likeable.rb', line 7

def self.included(model)
  model.instance_eval do
    has_many :likes, :conditions => {:positive => true}, :dependent => :delete_all, :as => :target
    has_many :dislikes, :conditions => {:positive => false}, :class_name => 'Like', :dependent => :delete_all, :as => :target
  end
end

Instance Method Details

#update_likes_counterInteger


15
16
17
18
# File 'lib/diaspora/likeable.rb', line 15

def update_likes_counter
  self.class.where(:id => self.id).
    update_all(:likes_count => self.likes.count)
end