comment liking

This commit is contained in:
Kyle Drake 2014-05-05 11:58:11 -07:00
parent 8210670122
commit 51a85a0b03
9 changed files with 125 additions and 29 deletions

View file

@ -2,4 +2,31 @@ class Comment < Sequel::Model
include Sequel::ParanoidDelete
many_to_one :event
many_to_one :actioning_site, class: :Site
end
one_to_many :comment_likes
def liking_site_names
comment_likes.collect {|comment_like| comment_like.actioning_site.username }
end
def site_likes?(site)
comment_likes_dataset.filter(actioning_site_id: site.id).count > 0
end
def site_like(site)
add_comment_like actioning_site_id: site.id
end
def site_unlike(site)
comment_likes_dataset.filter(actioning_site_id: site.id).delete
end
def toggle_site_like(site)
if site_likes? site
site_unlike site
false
else
site_like site
true
end
end
end