Skip to content

Commit

Permalink
Use LEFT JOIN instead of INNER JOIN
Browse files Browse the repository at this point in the history
To make results of `counts_query` includes records of which count is 0
  • Loading branch information
luvtechno committed Oct 9, 2013
1 parent 6234e1a commit d0c48b9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/counter_culture.rb
Expand Up @@ -101,7 +101,7 @@ def counter_culture_fix_counts(options = {})
# lives in
reverse_relation.each do |cur_relation|
reflect = relation_reflect(cur_relation)
counts_query = counts_query.joins("JOIN #{reflect.active_record.table_name} ON #{reflect.table_name}.id = #{reflect.active_record.table_name}.#{reflect.foreign_key}")
counts_query = counts_query.joins("LEFT JOIN #{reflect.active_record.table_name} ON #{reflect.table_name}.id = #{reflect.active_record.table_name}.#{reflect.foreign_key}")
end

# iterate in batches; otherwise we might run out of memory when there's a lot of
Expand Down

0 comments on commit d0c48b9

Please sign in to comment.