Sha256: ab2d7db43763c7e2977957a97e805a6dfea392558aeb8b109380209daad21df0

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

module ActiveRecord #:nodoc:
  module ConnectionAdapters #:nodoc:
    module OracleEnhancedDirty #:nodoc:

      module InstanceMethods
        private
        
        def field_changed?(attr, old, value)
          if column = column_for_attribute(attr)
            # RSI: added also :decimal type
            if (column.type == :integer || column.type == :decimal) && column.null && (old.nil? || old == 0)
              # For nullable integer columns, NULL gets stored in database for blank (i.e. '') values.
              # Hence we don't record it as a change if the value changes from nil to ''.
              # If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll
              # be typecast back to 0 (''.to_i => 0)
              value = nil if value.blank?
            # RSI: Oracle stores empty string '' or empty text (CLOB) as NULL
            # therefore need to convert empty string value to nil if old value is nil
            elsif (column.type == :string || column.type == :text) && column.null && old.nil?
              value = nil if value == ''
            else
              value = column.type_cast(value)
            end
          end

          old != value
        end
        
      end

    end
  end
end

if ActiveRecord::Base.instance_methods.include?('changed?')
  ActiveRecord::Base.class_eval do
    include ActiveRecord::ConnectionAdapters::OracleEnhancedDirty::InstanceMethods
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
rsim-activerecord-oracle_enhanced-adapter-1.1.9.90 lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
rsim-activerecord-oracle_enhanced-adapter-1.1.9.91 lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
rwc9u-activerecord-oracle_enhanced-adapter-1.1.9.3 lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
rwc9u-activerecord-oracle_enhanced-adapter-1.1.9.4 lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
rwc9u-activerecord-oracle_enhanced-adapter-1.1.9.5 lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
rwc9u-oracle-enhanced-1.1.9.4 lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
activerecord-oracle_enhanced-adapter-1.1.9 lib/active_record/connection_adapters/oracle_enhanced_dirty.rb