Sha256: bedcec8c1c7841101c742b93c4968195226e65aa2819c8040f8315bdb6c6f54a

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

require 'active_record'

if ActiveRecord::VERSION::STRING =~ /^3\.1/
  require 'active_record/reflection'
  require 'active_record/associations'
  require 'active_record/associations/belongs_to_polymorphic_association'

  module ActiveRecord
    module Reflection # :nodoc:
      class AssociationReflection
        def foreign_subtype
          @foreign_subtype ||= options[:foreign_subtype] || "#{name}_subtype"
        end
      end
    end
    
    # = Active Record Belongs To Polymorphic Association
    module Associations
      class BelongsToPolymorphicAssociation < BelongsToAssociation #:nodoc:
        private

          def replace_keys(record)
            super
            owner[reflection.foreign_type] = record && record.class.base_class.name
            owner[reflection.foreign_subtype] = record && record.class.sti_name
          end
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
store_base_sti_class_for_3_0-0.1.3 lib/store_base_sti_class_for_3_1.rb