I've noticed that because of the query_cache, if you write the value
of an attribute on an ActiveRecord object, the object will continue to
have that "dirty" value even if you ".reload" the object or try and
fetch it again from the DB.  Here's an example in a test case.  You
could stick this in QueryCacheExpiryTest:

  def test_write_attribute

    # With our without the query cache shouldn't this behave the same?
    task = Task.find(1)
    starting = task.starting
    task.starting = Time.now
    task.reload
    assert_equal starting, task.starting

    # But this assert will fail
    Task.cache do
      task = Task.find(1)
      task.starting = Time.now
      task.reload
      assert_equal starting, task.starting
    end
  end


Should the query cache get cleared when "write_attribute" is called?
I've started working on a patch,  couldn't it be as simple as this:

    def write_attribute_with_clears_cache(attr_name, value)
      if self.class.query_cache
        self.class.query_cache.clear_query_cache
      end
      write_attribute_without_clears_cache(attr_name, value)
    end
    alias_method_chain :write_attribute, :clears_cache


As something added to Base inside query_cache.rb?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to