rails 4:按包含字段查找
rails 4: find by includes field
在 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 中工作的查询?
尝试关注
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
在 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 中工作的查询?
尝试关注
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