added artists, comments
This commit is contained in:
21
app/logical/favorite.rb
Normal file
21
app/logical/favorite.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class Favorite
|
||||
def self.table_name_for(user)
|
||||
"favorites_#{user.id % 10}"
|
||||
end
|
||||
|
||||
def self.create(user, post)
|
||||
ActiveRecord::Base.connection.execute("INSERT INTO #{table_name_for(user)} (user_id, post_id) VALUES (#{user.id}, #{post.id})")
|
||||
end
|
||||
|
||||
def self.destroy(user, post)
|
||||
ActiveRecord::Base.connection.execute("DELETE FROM #{table_name_for(user)} WHERE user_id = #{user.id} AND post_id = #{post.id}")
|
||||
end
|
||||
|
||||
def self.destroy_all_for_post(post)
|
||||
ActiveRecord::Base.connection.execute("DELETE FROM #{table_name_for(user)} WHERE post_id = #{post.id}")
|
||||
end
|
||||
|
||||
def self.destroy_all_for_user(user)
|
||||
ActiveRecord::Base.connection.execute("DELETE FROM #{table_name_for(user)} WHERE user_id = #{user.id}")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user