added constraint for fav search

This commit is contained in:
albert
2011-11-16 13:12:02 -05:00
parent 710d584ec6
commit cce3fe0b64
10 changed files with 4 additions and 96 deletions

View File

@@ -1,4 +1,4 @@
class Favorite < ActiveRecord::Base
belongs_to :post
scope :for_user, lambda {|user_id| where("user_id = #{user_id}")}
scope :for_user, lambda {|user_id| where("user_id % 100 = #{user_id.to_i % 100} and user_id = #{user_id.to_i}")}
end

View File

@@ -176,7 +176,7 @@ class User < ActiveRecord::Base
module FavoriteMethods
def favorites
Favorite.where("user_id = ?", id).order("id desc")
Favorite.where("user_id % 100 = #{id % 100} and user_id = #{id}").order("id desc")
end
def add_favorite!(post)