我已经为一个表实现了ajax-datatables-rails,我使用group
获取带有查询的原始记录 class ListcontractorsDatatable < AjaxDatatablesRails::Base
def view_columns
# Declare strings in this format: ModelName.column_name
# or in aliased_join_table.column_name format
@view_columns ||= {
id: { source: "Contractor.id", cond: :eq },
name: { source: "Contractor.name" },
city: { source: "Contractor.city" },
ico: { source: "Contractor.ico" },
country: { source: "Contractor.country" },
count: {source: "Contract.count"}
}
end
def_delegators :@view, :link_to, :showcontractor_path, :content_tag
def data
records.map do |contractor|
{
# example:
id: contractor.id,
name: link_to(contractor.name, showcontractor_path(contractor.id)),
city: contractor.city,
ico: contractor.ico,
country: contractor.country,
count: contractor.count,
extlink: link_to(content_tag(:i,nil,class: 'fa fa-external-link'), 'https://www.somepage.com/'+contractor.ico.to_s)
}
end
end
private
def get_raw_records
Contractor.joins(:contracts).select("contractors.id,name,ico,city,country,count(resultinfo_id) as count")
.group("contractors.id,contractors.name,contractors.ico,contractors.city,contractors.country")
end
end
一切正常(排序,分页,所有列都正确),搜索除外。当我把任何东西都搜索到时我得到了错误
PG :: GroupingError:错误:不允许使用聚合函数 WHERE
我在查询分支0.4.0时找不到任何有组的工作解决方案。请你帮助我好吗? THX