Last active
          December 20, 2019 04:51 
        
      - 
      
- 
        Save ej2015/07f2959b74eb89740e8ca1a0a4e301b5 to your computer and use it in GitHub Desktop. 
    Rails scope does not cache
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | Rails cache SQL calls | |
| So suppose we have a model Author which has_many Book | |
| expect(author.books).to equal author.books | |
| If Book has a scope, say by_countries: | |
| scope :by_countries, -> c { where(countries: c) if c.present? } | |
| scoped queries are not cached: | |
| expect(author.books.by_countries(nil)).not_to equal author.books.by_countries(nil) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment