Module: EasyUnionSet::GroupMethods

Defined in:
lib/easy_union_set.rb

Instance Method Summary collapse

Instance Method Details

#&(ar_rel) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/easy_union_set.rb', line 6

def & ar_rel
  case ar_rel
  when ActiveRecord::Relation
    set = self.intersect(ar_rel)
    table_alias = arel_table.create_table_alias(set, table_name)

    ancestors.first.from(table_alias)
  else
    super
  end
end

#|(ar_rel) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/easy_union_set.rb', line 18

def | ar_rel
  case ar_rel
  when ActiveRecord::Relation
    union = self.union(ar_rel)
  when Hash
    ar_rel.assert_valid_keys(:all)
    union = self.union(:all, ar_rel[:all]) 
  else
    return super
  end
  
  table_alias = arel_table.create_table_alias(union, table_name)
  ancestors.first.from(table_alias)
end