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
when 1 then
finder_options[:joins] = joins
finder_options.delete( :include )
else
finder_options.delete( :joins )
finder_options[:include] = joins
end
end