Sha256: 23a3282fc1b2a3f17a08131ac846cbd0fbc317cbf5b8fe81209ece4fbf288424

Contents?: true

Size: 1.42 KB

Versions: 97

Compression:

Stored size: 1.42 KB

Contents

module ActiveRecord
  module Associations
    class BelongsToPolymorphicAssociation < AssociationProxy #:nodoc:
      def replace(record)
        if record.nil?
          @target = @owner[@reflection.primary_key_name] = @owner[@reflection.options[:foreign_type]] = nil
        else
          @target = (AssociationProxy === record ? record.target : record)

          unless record.new_record?
            @owner[@reflection.primary_key_name] = record.id
            @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s
          end

          @updated = true
        end

        loaded
        record
      end

      def updated?
        @updated
      end

      private
        def find_target
          return nil if association_class.nil?

          if @reflection.options[:conditions]
            association_class.find(
              @owner[@reflection.primary_key_name], 
              :conditions => conditions,
              :include    => @reflection.options[:include]
            )
          else
            association_class.find(@owner[@reflection.primary_key_name], :include => @reflection.options[:include])
          end
        end

        def foreign_key_present
          !@owner[@reflection.primary_key_name].nil?
        end

        def association_class
          @owner[@reflection.options[:foreign_type]] ? @owner[@reflection.options[:foreign_type]].constantize : nil
        end
    end
  end
end

Version data entries

97 entries across 97 versions & 7 rubygems

Version Path
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.14.0 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.14.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.14.3 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.14.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.14.4 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.15.0 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.15.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.15.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.15.4 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.15.3 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.15.6 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-1.15.5 lib/active_record/associations/belongs_to_polymorphic_association.rb