Class: ActiveRecord::Reflection::ThroughReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/store_base_sti_class_for_5_0.rb

Instance Method Summary collapse

Instance Method Details

#scope_chainObject



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/store_base_sti_class_for_5_0.rb', line 387

def scope_chain
  @scope_chain ||= begin
    scope_chain = source_reflection.scope_chain.map(&:dup)

    # Add to it the scope from this reflection (if any)
    scope_chain.first << scope if scope

    through_scope_chain = through_reflection.scope_chain.map(&:dup)

    if options[:source_type]
      type = foreign_type
      # START PATCH
      # original: source_type = options[:source_type]
      source_type =
        if ActiveRecord::Base.store_base_sti_class
          options[:source_type]
        else
          ([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
        end
      # END PATCH
      through_scope_chain.first << lambda { |object|
        where(type => source_type)
      }
    end

    # Recursively fill out the rest of the array from the through reflection
    scope_chain + through_scope_chain
  end
end