Class: Drippings::Scheduling

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/drippings/scheduling.rb

Class Method Summary collapse

Class Method Details

.dedup(scope, name) ⇒ Object

Parameters:

  • scope (ActiveRecord::Relation)
  • name (String)


8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/drippings/scheduling.rb', line 8

def self.dedup(scope, name)
  arel_on = Arel::Nodes::On.new(
    arel_table[:name].eq(name)
      .and(arel_table[:resource_id].eq(scope.arel_table[:id]))
      .and(arel_table[:resource_type].eq(scope.base_class.name))
  )

  arel_join = Arel::Nodes::OuterJoin.new(arel_table, arel_on)

  scope.joins(arel_join).merge(where(id: nil))
end