authlogic rails gem在sql查询中做了LOWER。Ruby on rails authlogic config(摆脱大小写检查)
SELECT * FROM `users` WHERE (LOWER(`users`.email) = '[email protected]') LIMIT 1
我想摆脱下部的,因为它似乎是由相当多的放缓查询。 我宁愿只是降低代码中的情况,因为这个查询看起来很昂贵。
我不确定在authlogic中更改此行为的位置。
谢谢!
authlogic rails gem在sql查询中做了LOWER。Ruby on rails authlogic config(摆脱大小写检查)
SELECT * FROM `users` WHERE (LOWER(`users`.email) = '[email protected]') LIMIT 1
我想摆脱下部的,因为它似乎是由相当多的放缓查询。 我宁愿只是降低代码中的情况,因为这个查询看起来很昂贵。
我不确定在authlogic中更改此行为的位置。
谢谢!
这个评论是从lib/authlogic/acts_as_authentic/login.rb
上述find_by_smart_case_login_field
方法:
# This method allows you to find a record with the given login. If you notice, with ActiveRecord you have the
# validates_uniqueness_of validation function. They give you a :case_sensitive option. I handle this in the same
# manner that they handle that. If you are using the login field and set false for the :case_sensitive option in
# validates_uniqueness_of_login_field_options this method will modify the query to look something like:
#
# first(:conditions => ["LOWER(#{quoted_table_name}.#{login_field}) = ?", login.downcase])
#
# If you don't specify this it calls the good old find_by_* method:
#
# find_by_login(login)
#
# The above also applies for using email as your login, except that you need to set the :case_sensitive in
# validates_uniqueness_of_email_field_options to false.
#
# The only reason I need to do the above is for Postgres and SQLite since they perform case sensitive searches with the
# find_by_* methods.
你要为你的电子邮件验证case_sensitive = false
?如果是这样,那么解决这个问题就不需要修补任何代码。
只是一个额外的说明。代码需要在一个块中传递给acts_as_authentic
acts_as_authentic do |c|
c.validates_uniqueness_of_email_field_options :case_sensitive => true
end
我没有设置电子邮件验证;这在authlogic中默认完成。你会在哪里设置? 我认为是这样的: validates_uniqueness_of:电子邮件:CASE_SENSITIVE =>:假 我想,在我的USER_SESSION模型,并得到了validates_uniqueness_of – djburdick 2010-05-26 00:53:02
一个未定义的方法这将是'validates_uniqueness_of_email_field_options'按照上面的片断,但如果你AREN将其设置在模型中,那么这不应该是原因。默认情况下,Authlogic不应该使用LOWER,所以它似乎认为它被告知忽略大小写 - 问题在于如何? – zetetic 2010-05-26 04:35:23
谢谢兄弟! 我刚刚添加了validates_uniqueness_of_email_field_options:case_sensitive => true 我想我必须明确地添加它,因为默认值与文档所说的不同。 – djburdick 2010-05-28 17:22:53