Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10840 (closed defect: fixed)

Opened 6 months ago

Last modified 5 months ago

[PATCH] Query Cache not expired by HABTM insert or delete

Reported by: john.andrews Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: query_cache habtm
Cc:

Description

When using has_and_belongs_to_many associations, the cache is not reset by an insert to that association. For example:

 ActiveRecord::Base.cache do
   c = Category.find(:first)
   p = Post.find(:first)
   p.categories << c  #does not reset cache
   Category.find      #hits cache
 end

The solution seems to be to change 2 calls in has_and_belongs_to_many_association.rb from connection.execute to connection.insert and connection.delete. This ensures that the query_cache is cleared after executing the insert or delete.

Attachments

query_cache_and_habtm.diff (3.2 kB) - added by john.andrews on 01/17/08 20:49:56.

Change History

01/17/08 20:49:56 changed by john.andrews

  • attachment query_cache_and_habtm.diff added.

01/17/08 22:28:00 changed by wagaman

+1

01/18/08 01:55:15 changed by rick

  • status changed from new to closed.
  • resolution set to fixed.

(In [8653]) Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]

02/10/08 01:02:41 changed by nzkoz

(In [8828]) 2-0-stable: Ensure that modifying has_and_belongs_to_many actions clear the query cache. References #10840 [john.andrews] Merging [8653]