Skip to content

Instantly share code, notes, and snippets.

@mrbrdo
Created September 25, 2013 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrbrdo/6700833 to your computer and use it in GitHub Desktop.
Save mrbrdo/6700833 to your computer and use it in GitHub Desktop.
class Photo < ActiveRecord::Base
scope :enabled, -> { where(photo: { enabled: true }) }
end
class Person < ActiveRecord::Base
has_one :display_photo, -> {
self.select_values = ["DISTINCT ON(photos.person_id) photos.*"]
instance_exec(&Photo.method(:enabled)).order('photos.person_id')
}, class_name: "Photo"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment