Sha256: b0e529a30605123efc53a4f69a47ea6fb4bf4d530b4e70746b6ca1f99f2a92c7
Contents?: true
Size: 627 Bytes
Versions: 1
Compression:
Stored size: 627 Bytes
Contents
module Likeable extend ActiveSupport::Concern included do belongs_to :target, polymorphic: true has_many :likes, -> { where(positive: true) }, dependent: :delete_all, as: :target has_many :likers, class_name: 'User', through: :likes, source: :user has_many :dislikes, -> { where(positive: false) }, class_name: 'Like', dependent: :delete_all, as: :target has_many :dislikers, class_name: 'User', through: :dislikes, source: :user end def update_likes_counter self.class.where(id: self.id).update_all likes_count: self.likes.count, dislikes_count: self.dislikes.count end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
voluntary-0.2.2 | app/models/concerns/likeable.rb |