Skip to content

Instantly share code, notes, and snippets.

@ej2015
Last active December 20, 2019 04:51
Show Gist options
  • Save ej2015/07f2959b74eb89740e8ca1a0a4e301b5 to your computer and use it in GitHub Desktop.
Save ej2015/07f2959b74eb89740e8ca1a0a4e301b5 to your computer and use it in GitHub Desktop.
Rails scope does not cache
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