This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# our multi_group http://rails.lighthouseapp.com/projects/8994/tickets/120-patch-activerecord-calculations-only-accept-one-grouping-field# | |
# isn't updated for 2.2 yet. In the meantime, this poor man's version gives you the same results with some delimitter tom foolery. | |
# | |
# note: be careful to ensure that your group_by do not use the delimitter | |
# usage: | |
# self.multi_count(:id, :distinct => true, :group => [:symptom_id, :treatment_id]) | |
# [[["138", "1018"], 187], [["138", "427"], 373], [["6", "1018"], 197], [["6", "427"], 393]] | |
class ActiveRecord::Base | |
def self.multi_count(field, opts = {}) | |
fq_field_name = "#{table_name}.#{field}" |