Skip to content

Instantly share code, notes, and snippets.

@ecin
Created November 10, 2010 03:46
Show Gist options
  • Save ecin/670317 to your computer and use it in GitHub Desktop.
Save ecin/670317 to your computer and use it in GitHub Desktop.
For tumblr post.
class Search < ActiveRecord::Base
belongs_to :searchable, :polymorphic => true
# This will actually work now, no more
# n + 1 query problems, yay!
default_scope :include => :searchable
def hash
searchable_id.hash + searchable_type.hash
end
def eql?(result)
searchable_type == result.searchable_type and
searchable_id == result.searchable_id
end
# And view results can't be updated, so...
def readonly?
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment