lib/acts-as-joinable.rb in acts-as-joinable-0.1.3 vs lib/acts-as-joinable.rb in acts-as-joinable-0.1.4

- old
+ new

@@ -1,5 +1,6 @@ +# https://rails.lighthouseapp.com/projects/8994/tickets/5182-activerecordcalculations-returns-incorrect-data-when-grouping-by-multiple-fields module ActsAsJoinable def self.models unless @models if defined?(Rails) @@ -40,9 +41,18 @@ end include ActsAsJoinable::Core end end + end + + # Group.count_joins(:as => :parent, :conditions) + def count_joins(options = {}) + relationship = options.delete(:as) || :parent + conditions = options[:conditions] || {} + conditions["#{relationship.to_s}_type".to_sym] = ([self.name] + (self.send(:subclasses) - self.included_modules).map(&:name)).flatten.uniq + group = options[:group] || "#{relationship}_id" + ActsAsJoinable::Relationship.count(:conditions => conditions, :group => group) end def acts_as_joinable acts_as_joinable_on end \ No newline at end of file