Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Search < ActiveRecord::Base
  2. belongs_to :searchable, :polymorphic => true
  3.  
  4. # This will actually work now, no more
  5. # n + 1 query problems, yay!
  6. default_scope :include => :searchable
  7.  
  8. def hash
  9. searchable_id.hash + searchable_type.hash
  10. end
  11.  
  12. def eql?(result)
  13. searchable_type == result.searchable_type and
  14. searchable_id == result.searchable_id
  15. end
  16.  
  17. # And view results can't be updated, so...
  18. def readonly?
  19. true
  20. end
  21. end
Add Comment
Please, Sign In to add comment