Module: Dase::ARRelationInstanceMethods

Defined in:
lib/dase/mp_active_record.rb

Instance Method Summary collapse

Instance Method Details

#dase_valuesObject



3
4
5
# File 'lib/dase/mp_active_record.rb', line 3

def dase_values
  @dase_values ||= {}
end

#includes_count_of(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dase/mp_active_record.rb', line 7

def includes_count_of(*args)
  options = args.extract_options!
  sanitize_includes_count_of_options(args, options)
  return self if args.empty?
  clone.tap do |relation|
    args.each do |arg|
      counter_name = (options[:as] || "#{arg}_count").to_sym
      relation.dase_values[counter_name] = options.merge(as: counter_name, association: arg.to_sym)
    end
  end
end

#merge(other) ⇒ Object



19
20
21
22
23
# File 'lib/dase/mp_active_record.rb', line 19

def merge(other)
  super(other).tap do |result|
    result.dase_values.merge!(other.dase_values || {}) if other # other == nil is fine too
  end
end