method

sanitize_sql_hash_for_conditions

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ClassMethods

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v4.2.9) is shown here.

sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name) protected

Sanitizes a hash of attribute/value pairs into SQL conditions for a WHERE clause.

{ name: "foo'bar", group_id: 4 }
  # => "name='foo''bar' and group_id= 4"
{ status: nil, group_id: [1,2,3] }
  # => "status IS NULL and group_id IN (1,2,3)"
{ age: 13..18 }
  # => "age BETWEEN 13 AND 18"
{ 'other_records.id' => 7 }
  # => "`other_records`.`id` = 7"
{ other_records: { id: 7 } }
  # => "`other_records`.`id` = 7"

And for value objects on a composed_of relationship:

{ address: Address.new("123 abc st.", "chicago") }
  # => "address_street='123 abc st.' and address_city='chicago'"
Show source
Register or log in to add new notes.