Sha256: 692ee84a1ba2cae1d5ebe6286d3a7789cf0fe54a94fdc2240f36324f7bf1151d

Contents?: true

Size: 540 Bytes

Versions: 1

Compression:

Stored size: 540 Bytes

Contents

module PolymorphicConstraints
  module Utils
    module PolymorphicModelFinder
      def get_polymorphic_models(relation)
        Rails.application.eager_load!
        ActiveRecord::Base.descendants.select do |klass|
          contains_polymorphic_relation?(klass, relation)
        end
      end

      private

      def contains_polymorphic_relation?(model_class, relation)
        associations = model_class.reflect_on_all_associations
        associations.map{ |r| r.options[:as] }.include?(relation.to_sym)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polymorphic_constraints-1.0.0 lib/polymorphic_constraints/utils/polymorphic_model_finder.rb