def map_reflection_for( path )
raise "reflection for #{path.inspect} already exists" unless reflections[path].nil?
reflection = path.empty? ? top_level_model : begin
parent = reflection_for( path[0..-2] )
if !parent.respond_to?(:proxy_reflection) and parent.respond_to?(:klass)
parent.klass.reflect_on_association( path.last )
else
parent.reflect_on_association( path.last )
end
rescue
parent.reflect_on_association( path.last )
end
raise "invalid path #{path.inspect}" if reflection.nil?
reflections[path] = reflection
map_table_alias_for( path )
if !reflection.respond_to?(:proxy_reflection) and !reflection.respond_to?(:proxy_scope) and reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
join_table_path = path[0..-2] + [reflection.options[:through]]
reflection_for(join_table_path, true)
end
reflection
end