module ActiveRecord::Reflection

def self.add_aggregate_reflection(ar, name, reflection)

def self.add_aggregate_reflection(ar, name, reflection)
  ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection)
end

def self.add_reflection(ar, name, reflection)

def self.add_reflection(ar, name, reflection)
  ar._reflections = ar._reflections.merge(name.to_s => reflection)
end

def self.create(macro, name, scope, options, ar)

def self.create(macro, name, scope, options, ar)
  klass = case macro
          when :composed_of
            AggregateReflection
          when :has_many
            HasManyReflection
          when :has_one
            HasOneReflection
          when :belongs_to
            BelongsToReflection
          else
            raise "Unsupported Macro: #{macro}"
          end
  reflection = klass.new(name, scope, options, ar)
  options[:through] ? ThroughReflection.new(reflection) : reflection
end