DataTables全局搜索缺少FROM子句



我正在使用datatables gem来显示包含两个相关表的表。因此,它从三个不同的表中提取并显示列。

这很好,我甚至可以按所需的列进行排序。不幸的是,全局搜索功能被破坏了。SQL语句的格式似乎不正确。它找不到在上执行where子句的表。

错误为:

PG::未定义表:错误:表"items"缺少FROM子句条目第1行:SELECT COUNT

我使用的模型位于其他两个模型之间,每个模型都有多对1的关系:Items(1)-(M)ItemStores(M)-(1)Stores。

我的原始数据查询是:

def get_raw_records
  # insert query here
  ItemStore.includes([ :item, :store ]).all 
end

index.json.builder

json.item_stores @item_stores do |item_store|
  json.id item_stores.id
  json.item.image_path item_store.item.image_path
  json.store_id item_stores.store_id
  json.price item_stores.price
  json.items item_store.items do |item|
    json.(item, :description, :price, :image_path)
  end
  json.stores item_store.stores do |store|
    json.(store, :store_name)
  end
  json.url item_stores_url(i, format: :json)
end

我不知道我能做些什么来修复连接到全局搜索的底层SQL。。。任何帮助都将不胜感激。谢谢

找到答案!

get_raw_records中的查询应为:

ItemStore.includs(:item,:store).references

最新更新