Files
danbooru/app/models/favorite.rb
albert 073ab8ee96 * Fixed favorites deletion
* Fixed parenting when dealing with post deletion
2012-01-06 18:20:18 -05:00

10 lines
422 B
Ruby

class Favorite < ActiveRecord::Base
belongs_to :post
scope :for_user, lambda {|user_id| where("user_id % 100 = #{user_id.to_i % 100} and user_id = #{user_id.to_i}")}
# this is necessary because there's no trigger for deleting favorites
def self.destroy_all(hash)
connection.execute("delete from favorites_#{hash[:user_id] % 100} where user_id = #{hash[:user_id]} and post_id = #{hash[:post_id]}")
end
end