mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
stop caching the class on the statement cache object
This commit is contained in:
parent
8de3c433ef
commit
2d3969c82f
3 changed files with 15 additions and 15 deletions
|
@ -139,7 +139,7 @@ module ActiveRecord
|
|||
where(key => params[key]).limit(1)
|
||||
}
|
||||
}
|
||||
record = s.execute(key => id).first
|
||||
record = s.execute({key => id}, self, connection).first
|
||||
unless record
|
||||
raise RecordNotFound, "Couldn't find #{name} with '#{primary_key}'=#{id}"
|
||||
end
|
||||
|
@ -167,7 +167,7 @@ module ActiveRecord
|
|||
}
|
||||
}
|
||||
begin
|
||||
s.execute(hash).first
|
||||
s.execute(hash, self, connection).first
|
||||
rescue TypeError => e
|
||||
raise ActiveRecord::StatementInvalid.new(e.message, e)
|
||||
end
|
||||
|
|
|
@ -74,19 +74,19 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
attr_reader :bind_map, :query_builder, :klass
|
||||
attr_reader :bind_map, :query_builder
|
||||
|
||||
def initialize(block = Proc.new)
|
||||
relation = block.call Params.new
|
||||
@bind_map = BindMap.new relation.bind_values
|
||||
@klass = relation.klass
|
||||
@query_builder = make_query_builder @klass.connection, relation.arel
|
||||
klass = relation.klass
|
||||
@query_builder = make_query_builder klass.connection, relation.arel
|
||||
end
|
||||
|
||||
def execute(params)
|
||||
def execute(params, klass, connection)
|
||||
bind_values = bind_map.bind params
|
||||
|
||||
sql = query_builder.sql_for bind_values, klass.connection
|
||||
sql = query_builder.sql_for bind_values, connection
|
||||
|
||||
klass.find_by_sql sql, bind_values
|
||||
end
|
||||
|
|
|
@ -19,9 +19,9 @@ module ActiveRecord
|
|||
Book.where(:name => params[:name])
|
||||
end
|
||||
|
||||
b = cache.execute name: "my book"
|
||||
b = cache.execute({ name: "my book" }, Book, Book.connection)
|
||||
assert_equal "my book", b[0].name
|
||||
b = cache.execute name: "my other book"
|
||||
b = cache.execute({ name: "my other book" }, Book, Book.connection)
|
||||
assert_equal "my other book", b[0].name
|
||||
end
|
||||
|
||||
|
@ -34,9 +34,9 @@ module ActiveRecord
|
|||
Book.where(id: params[:id])
|
||||
end
|
||||
|
||||
b = cache.execute id: b1.id
|
||||
b = cache.execute({ id: b1.id }, Book, Book.connection)
|
||||
assert_equal b1.name, b[0].name
|
||||
b = cache.execute id: b2.id
|
||||
b = cache.execute({ id: b2.id }, Book, Book.connection)
|
||||
assert_equal b2.name, b[0].name
|
||||
end
|
||||
|
||||
|
@ -59,7 +59,7 @@ module ActiveRecord
|
|||
|
||||
Book.create(name: "my book", author_id: 4)
|
||||
|
||||
books = cache.execute({})
|
||||
books = cache.execute({}, Book, Book.connection)
|
||||
assert_equal "my book", books[0].name
|
||||
end
|
||||
|
||||
|
@ -72,7 +72,7 @@ module ActiveRecord
|
|||
molecule = salty.molecules.create(name: 'dioxane')
|
||||
molecule.electrons.create(name: 'lepton')
|
||||
|
||||
liquids = cache.execute({})
|
||||
liquids = cache.execute({}, Book, Book.connection)
|
||||
assert_equal "salty", liquids[0].name
|
||||
end
|
||||
|
||||
|
@ -85,13 +85,13 @@ module ActiveRecord
|
|||
Book.create(name: "my book")
|
||||
end
|
||||
|
||||
first_books = cache.execute({})
|
||||
first_books = cache.execute({}, Book, Book.connection)
|
||||
|
||||
3.times do
|
||||
Book.create(name: "my book")
|
||||
end
|
||||
|
||||
additional_books = cache.execute({})
|
||||
additional_books = cache.execute({}, Book, Book.connection)
|
||||
assert first_books != additional_books
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue