Sha256: 68040998424cc126fd99bb6ec1e226e424cd533623da4480b32558d2d66fa124

Contents?: true

Size: 1.46 KB

Versions: 42

Compression:

Stored size: 1.46 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)

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

          @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],
              :select     => @reflection.options[:select],
              :conditions => conditions,
              :include    => @reflection.options[:include]
            )
          else
            association_class.find(@owner[@reflection.primary_key_name], :select => @reflection.options[:select], :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

42 entries across 41 versions & 13 rubygems

Version Path
radiant-0.7.2 vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
vibes-bj-1.2.2 spec/rails_root/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
vibes-bj-1.2.1 spec/rails_root/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
nbudin-castronaut-0.7.5 vendor/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activerecord/pkg/activerecord-2.2.2/lib/active_record/associations/belongs_to_polymorphic_association.rb
factorylabs-castronaut-0.7.5 vendor/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-2.2.3 lib/active_record/associations/belongs_to_polymorphic_association.rb
webroar-0.2.2 src/admin_panel/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-2.1.0 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-2.1.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-2.1.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-2.2.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-2.3.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
antfarm-0.3.0 rails/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
antfarm-0.4.0 rails/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
mack-active_record-0.8.2 lib/gems/activerecord-2.2.2/lib/active_record/associations/belongs_to_polymorphic_association.rb
mack-active_record-0.8.3.1 lib/gems/activerecord-2.2.2/lib/active_record/associations/belongs_to_polymorphic_association.rb
mack-active_record-0.8.3 lib/gems/activerecord-2.2.2/lib/active_record/associations/belongs_to_polymorphic_association.rb
radiant-0.7.0 vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb