Rails is caching results from a scope

I have a model that has a pivot area that retrieves only a couple of important fields:

class Cupcake < ActiveRecord::Base
  scope :summary, select([:id, :name])
end

If I call this area, then call

Cupcake.find(id)

I get a record with id and name attributes filled only.

Is there some kind of option that I can pass to the find command to force it to go to the database? Also, should they not generate completely different sql statements, and therefore will activerecord be forced to go to the database?

Note. I am using Rails 3.2.3 with pg gem

+3
source share
1 answer

You can use uncached method. See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/QueryCache.html#method-i-uncached

:

uncached_cupcake = ActiveRecord::Base.uncached do
  Cupcake.find(id)
end

, .

0

All Articles