Sha256: 780010d668a682c2144bbdb8498b87d02173baa89e0251a39fc78fcb7bc0a904

Contents?: true

Size: 862 Bytes

Versions: 2

Compression:

Stored size: 862 Bytes

Contents

class Change < MLS::Model
  self.inheritance_column = nil
  
  belongs_to :subject, :polymorphic => true
  has_many :event_actions, :as => :action
  has_many :mistakes
  
  # Returns the association instance for the given name, instantiating it if it doesn't already exist
  def association(name) #:nodoc:
    association = super

    return association if name.to_s != 'subject'

    association.instance_exec do
      def klass
        type = owner[reflection.foreign_type]
        type.presence && type.constantize
      rescue NameError
        nil
      end

      def reader(force_reload=false)
        if klass
          if force_reload
            klass.uncached { reload }
          elsif !loaded? || stale_target?
            reload
          end

          target
        else
          nil
        end
      end
    end

    association
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mls-1.5.0 lib/mls/change.rb
mls-1.4.3 lib/mls/change.rb