Created
November 10, 2010 03:46
-
-
Save ecin/670317 to your computer and use it in GitHub Desktop.
For tumblr post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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