Skip to content
Commits on Dec 7, 2012
  1. @carlosantoniodasilva

    Unscope update_column(s) query to ignore default scope

    carlosantoniodasilva committed
    When applying default_scope to a class with a where clause, using
    update_column(s) could generate a query that would not properly update
    the record due to the where clause from the default_scope being applied
    to the update query.
    
        class User < ActiveRecord::Base
          default_scope where(active: true)
        end
    
        user = User.first
        user.active = false
        user.save!
    
        user.update_column(:active, true) # => false
    
    In this situation we want to skip the default_scope clause and just
    update the record based on the primary key. With this change:
    
        user.update_column(:active, true) # => true
    
    Backport of #8436 fix.
    
    Conflicts:
    	activerecord/CHANGELOG.md
    	activerecord/lib/active_record/persistence.rb
    	activerecord/test/cases/persistence_test.rb
Commits on Oct 29, 2012
  1. @carlosantoniodasilva @rafaelfranca

    Merge pull request #8053 from henrik/update_columns_with_primary_key

    carlosantoniodasilva committed with rafaelfranca
    Unbreak update_column/update_columns for the primary key attribute.
    Conflicts:
    	activerecord/CHANGELOG.md
    	activerecord/lib/active_record/persistence.rb
    	activerecord/test/cases/persistence_test.rb
Something went wrong with that request. Please try again.