3
如何將這個MySQL的WHERE翻譯爲ActiveRecord:condition?ActiveRecord中的SQL LENGTH?
SELECT * FROM users WHERE LENGTH(users.last_name) < 3
謝謝!
如何將這個MySQL的WHERE翻譯爲ActiveRecord:condition?ActiveRecord中的SQL LENGTH?
SELECT * FROM users WHERE LENGTH(users.last_name) < 3
謝謝!
User.find(:all, :conditions => ["LENGTH(last_name) < ?", 3])
,或者您可以使用find_by_sql
User.find_by_sql("SELECT * FROM users WHERE LENGTH(users.last_name) < 3")