Module: ActiveRecordExtended::RelationPatch::Merger

Defined in:
lib/active_record_extended/active_record/relation_patch.rb

Instance Method Summary collapse

Instance Method Details

#mergeObject



16
17
18
19
20
21
# File 'lib/active_record_extended/active_record/relation_patch.rb', line 16

def merge
  merge_ctes!
  merge_union!
  merge_windows!
  super
end

#merge_ctes!Object



37
38
39
40
41
42
43
44
45
# File 'lib/active_record_extended/active_record/relation_patch.rb', line 37

def merge_ctes!
  return unless other.with_values?

  if other.recursive_value? && !relation.recursive_value?
    relation.with!(:chain).recursive(other.cte)
  else
    relation.with!(other.cte)
  end
end

#merge_union!Object



23
24
25
26
27
28
29
# File 'lib/active_record_extended/active_record/relation_patch.rb', line 23

def merge_union!
  return if other.unionize_storage.empty?

  relation.union_values          += other.union_values
  relation.union_operations      += other.union_operations
  relation.union_ordering_values += other.union_ordering_values
end

#merge_windows!Object



31
32
33
34
35
# File 'lib/active_record_extended/active_record/relation_patch.rb', line 31

def merge_windows!
  return unless other.window_values?

  relation.window_values |= other.window_values
end