use*_*684 2 mysql activerecord ruby-on-rails
在 Rails 3 我有这个查询:
Supporter.includes(:person).where("concat(club_member_number, ' ', people.surname, ' ', people.name) LIKE ?", term)
Run Code Online (Sandbox Code Playgroud)
但是在 Rails 4 中,它通过了一个错误:
ActiveRecord::StatementInvalid Exception: Mysql2::Error: Unknown column 'person.surname'
Run Code Online (Sandbox Code Playgroud)
我如何更改它在 Rails 4 中工作的查询?
尝试以下
Supporter.eager_load(:person).where("concat(club_member_number, ' ', people.surname, ' ', people.name) LIKE ?", term)
Run Code Online (Sandbox Code Playgroud)
或references(:person)与includes
Supporter.includes(:person).where("concat(club_member_number, ' ', people.surname, ' ', people.name) LIKE ?", term).references(:person)
Run Code Online (Sandbox Code Playgroud)
参考这个