Class: ActiveRecord::Relation::WhereClauseFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord/monkey_patch/rails5_0.rb,
lib/activerecord/monkey_patch/rails5_1.rb,
lib/activerecord/monkey_patch/rails5_2.rb

Instance Method Summary collapse

Instance Method Details

#build(opts, other) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/activerecord/monkey_patch/rails5_0.rb', line 201

def build(opts, other)
  binds = []

  case opts
  when String, Array
    parts = [klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
  when Hash
    opts = ActiveRecord::MonkeyPatch.adjust_timezone_offset(opts)

    attributes = predicate_builder.resolve_column_aliases(opts)
    attributes = klass.send(:expand_hash_conditions_for_aggregates, attributes)
    attributes.stringify_keys!

    attributes, binds = predicate_builder.create_binds(attributes)

    parts = predicate_builder.build_from_hash(attributes)
  when Arel::Nodes::Node
    parts = [opts]
    binds = other
  else
    raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
  end

  WhereClause.new(parts, binds)
end