def rebuild_join_options!
      joins = (finder_options[:joins] || []) + (finder_options[:includes] || [])

      reflections.keys.each do |path|
        next if path.empty? or @join_table_joins.include?(path)

        existing_join = joins.find do |join|
          existing_path = join_to_path(join)
          min_length = [existing_path.length, path.length].min
          existing_path.first(min_length) == path.first(min_length)
        end

        if existing_join
          if join_to_path(existing_join).length < path.length
            joins[joins.index(existing_join)] = path_to_join(path)
          end
        else
          joins << path_to_join(path)
        end
      end

      case obligation_conditions.length
      when 0 then
        # No obligation conditions means we don't have to mess with joins or includes at all.
      when 1 then
        finder_options[:joins] = joins
        finder_options.delete( :include )
      else
        finder_options.delete( :joins )
        finder_options[:include] = joins
      end
    end
def rebuild_join_options!
      joins = (finder_options[:joins] || []) + (finder_options[:includes] || [])

      reflections.keys.each do |path|
        next if path.empty? or @join_table_joins.include?(path)

        existing_join = joins.find do |join|
          existing_path = join_to_path(join)
          min_length = [existing_path.length, path.length].min
          existing_path.first(min_length) == path.first(min_length)
        end

        if existing_join
          if join_to_path(existing_join).length < path.length
            joins[joins.index(existing_join)] = path_to_join(path)
          end
        else
          joins << path_to_join(path)
        end
      end

      case obligation_conditions.length
      when 0 then
        # No obligation conditions means we don't have to mess with joins or includes at all.
      when 1 then
        finder_options[:joins] = joins
        finder_options.delete( :include )
      else
        finder_options.delete( :joins )
        finder_options[:include] = joins
      end
    end
Parses all of the defined obligation joins and defines the scope's :joins or :includes option.
 TODO: Support non-linear association paths.  Right now, we just break down the longest path parsed.