better finder
parent
055e2211bc
commit
dec7581cec
|
@ -49,14 +49,12 @@ class Photo < ActiveRecord::Base
|
||||||
# Finds a Photo that the requested user can vote on by checking it against
|
# Finds a Photo that the requested user can vote on by checking it against
|
||||||
# all of the photos previously voted.
|
# all of the photos previously voted.
|
||||||
#
|
#
|
||||||
def self.next_available_votable_photo(user)
|
def self.next_available_votable_photo(user, include_facebook = false)
|
||||||
pids = Vote.voted_photo_ids(user)
|
pids = Vote.voted_photo_ids(user)
|
||||||
c = if pids.empty?
|
c = []
|
||||||
nil
|
c << "photos.id NOT IN (#{pids.join(',')})" unless pids.empty?
|
||||||
else
|
c << "photos.facebook_id IS NULL" unless include_facebook
|
||||||
"photos.id NOT IN (#{pids.join(',')})"
|
self.find :first, :conditions => c.join(' AND '), :order => 'id ASC'
|
||||||
end
|
|
||||||
self.find :first, :conditions => c, :order => 'id ASC'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
Reference in New Issue