Module: ActiveRecord::ActsAs::QueryMethods

Defined in:
lib/active_record/acts_as/querying.rb

Instance Method Summary collapse

Instance Method Details

#where!(opts, *rest) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_record/acts_as/querying.rb', line 4

def where!(opts, *rest)
  if acting_as? && opts.is_a?(Hash)
    if table_name_opts = opts.delete(table_name)
      opts = opts.merge(table_name_opts)
    end

    # Filter out the conditions that should be applied to the `acting_as_model`, which are
    # those that neither target specific tables explicitly (where the condition value
    # is a hash or the condition key contains a dot) nor are attributes of the submodel.
    opts, acts_as_opts = opts.stringify_keys.partition do |k, v|
      v.is_a?(Hash) ||
      k =~ /\./     ||
      column_names.include?(k.to_s) ||
      attribute_method?(k.to_s)
    end.map(&:to_h)

    if acts_as_opts.any?
      opts[acting_as_model.table_name] = acts_as_opts
    end
  end

  super opts, *rest
end