我正在尝试创建一个搜索过滤器,所有参数都是复选框的名称,因此它们是填充了 id 值的数组。
@sql_query = ''
if filters_benefit_type.nil? == false
@sql_query = 'id_benefit_type = (:benefit_types)'
end
if filters_category.nil? == false
if filters_benefit_type.nil? == false
@sql_query = @sql_query + ' AND '
end
@sql_query = @sql_query + 'id_subcategory = (:company_subcategorys)'
end
if filters_zone.nil? == false
if filters_category.nil? == false
@sql_query = @sql_query + ' AND '
end
@sql_query = 'zone = (:zones)'
end
@companys = Company
.joins(:subsidiary)
.joins(:benefit)
.where(@sql_query,
:benefit_types => filters_benefit_type,
:company_subcategorys => filters_category,
:zones => filters_zone
)
这引发了以下错误:
Mysql2::Error: Operand should contain 1 column(s):
有任何想法吗 ?我想我在做 .joins 和 .where 错误...