我正在将带有 SearchLogic 的 Rails-2.3 编写的应用程序转换为带有Arel 和 MetaWhere 的 Rails-3.0 ,并且我正在运行一个我不知道如何编写的操作。
旧代码是:
if params[:city] && params[:city].respond_to?(:each)
users = users.person_address_city_like_any(params[:city])
end
这样做是LIKE
对 params[:city] 数组中的每个项目进行匹配。
当只有一个搜索词时,这在 MetaWhere 中很容易:
users = users.where(:person => { :address => { :city.matches => '%city1%' } })
但是我如何用任意数量的城市写这个?