Class: ActiveRecord::Reflection::ThroughReflection

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

Instance Method Summary collapse

Instance Method Details

#conditionsObject



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/store_base_sti_class_for_3_1.rb', line 270

def conditions
  @conditions ||= begin
    conditions = source_reflection.conditions.map { |c| c.dup }

    # Add to it the conditions from this reflection if necessary.
    conditions.first << options[:conditions] if options[:conditions]

    through_conditions = through_reflection.conditions

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

    # Recursively fill out the rest of the array from the through reflection
    conditions += through_conditions

    # And return
    conditions
  end
end