Module: CanvasSync::Concerns::UserViaPseudonym::RelationHook

Extended by:
ActiveSupport::Concern
Defined in:
lib/canvas_sync/concerns/user_via_pseudonym.rb

Instance Method Summary collapse

Instance Method Details

#where!(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/canvas_sync/concerns/user_via_pseudonym.rb', line 8

def where!(*args)
  # Check the model class rather than the relation. ActiveRecord::Relation#respond_to?
  # builds the relation's arel as a side effect (via respond_to_missing?), which marks
  # the relation immutable and makes the super call below raise ImmutableRelation on
  # Rails < 6 (e.g. during schema load).
  return super unless klass.respond_to?(:users_via_pseudonym)

  super.tap do |q|
    args.select { |a| a.is_a?(Hash) }.each do |hash|
      hash.each do |key, value|
        next unless users_via_pseudonym.key?(key)
        q.joins!(key).references!(Arel::Nodes::SqlLiteral.new(key.to_s))
      end
    end
  end
end