Search code examples
ruby-on-rails-2

rails find_by_name getting wrong result


I'm working on a rails 2 project. I'm trying to fetch a record from tags table by using find_by_* . Its giving different result.

May I know why is this working like this?

In my model:

existing = user.tags.find_by_name(tag)

in Log:

SELECT * FROM `tags` WHERE (`tags`.`name` = 'Ror') AND (`tags`.user_id = 1) LIMIT 1

RuntimeError (#<Tag id: 980191043, user_id: 1, name: "rOr", created_at: "2014-09-09 12:18:55", updated_at: "2014-09-09 12:18:55">):

Solution

  • Are you using MySQL?

    If so it is likely it is doing a case insensitive comparison. Whether MySQL is case sensitive is based around the field collation of the column: http://dev.mysql.com/doc/refman/5.0/en/charset-column.html