Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/includes-count.rb
Instance Attribute Summary collapse
-
#includes_counts_values ⇒ Object
Returns the value of attribute includes_counts_values.
Instance Method Summary collapse
Instance Attribute Details
#includes_counts_values ⇒ Object
Returns the value of attribute includes_counts_values.
113 114 115 |
# File 'lib/includes-count.rb', line 113 def includes_counts_values @includes_counts_values end |
Instance Method Details
#includes_count(*args) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/includes-count.rb', line 115 def includes_count(*args) args.reject! {|a| a.blank? } return self if args.empty? relation = clone (relation.includes_counts_values ||= []) << args relation end |
#to_a_with_includes_count ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/includes-count.rb', line 125 def to_a_with_includes_count return @records if loaded? to_a_without_includes_count (includes_counts_values || []).each do |association_with_opts| association, opts = association_with_opts ActiveRecord::Associations::CountPreloader.new(@records, [association], opts).run end @records end |