在Rails 3中,我有这个问题:
Supporter.includes(:person).where("concat(club_member_number, ' ', people.surname, ' ', people.name) LIKE ?", term)
然而在Rails 4中它出现了一个错误:
ActiveRecord::StatementInvalid Exception: Mysql2::Error: Unknown column 'person.surname'
如何在Rails 4中更改查询?
答案 0 :(得分:4)
尝试以下
Supporter.eager_load(:person).where("concat(club_member_number, ' ', people.surname, ' ', people.name) LIKE ?", term)
或将references(:person)
与includes
Supporter.includes(:person).where("concat(club_member_number, ' ', people.surname, ' ', people.name) LIKE ?", term).references(:person)
参考this