buren / association_count

Small gem to include association counts where they are needed.
MIT License
3 stars 2 forks source link

user left_outer_joins instead of joins for more complete results #2

Closed lostapathy closed 6 years ago

lostapathy commented 6 years ago

This users left_outer_joins instead of joins so that associations with zero associated records are included in the results.

Resolves https://github.com/trialbee/association_count/issues/6

buren commented 6 years ago

Hi! Thank you @lostapathy.

I've merged this, so left outer joins will be the default behaviour, and I also added the ability to configure:

# Per method
Author.all.include_post_count(join_type: :joins) # old behaviour

# Per model
class Author < ApplicationRecord
  has_many :posts
  can_count :posts, join_type: :joins
end

# global configuration
AssociationCount.configure do |config|
  config.distinct = false
  config.join_type = :joins # or left_outer_joins
end
lostapathy commented 6 years ago

Thanks for merging this! Glad to have found this gem, it's been a big hel.

buren commented 6 years ago

@lostapathy v1.1.0 released to RubyGems 🎉