0

I just encountered something rather surprising with the where method. When I query something like MyModel.where(id: '121-fake'), it gets translated to id = 121 in SQL, i.e. ActiveRecord appears to remove what's after the dash. This seems to only happen when I query with id. Can anyone help point me to where this is implemented? Thanks.

EJAg
  • 3,210
  • 2
  • 14
  • 22

1 Answers1

1

The id field is probably of an integer type, so ActiveRecord basically casts the parameter to an integer by calling to_i:

 '121-fake'.to_i # -> 121
eugen
  • 8,916
  • 11
  • 57
  • 65