【发布时间】:2015-04-04 14:45:32
【问题描述】:
我正在使用datatables gem 来显示一个包含两个相关表的表。结果,它从三个不同的表中拉入并显示列。
这工作正常,我什至可以按所需的列进行排序。不幸的是,全局搜索功能已损坏。似乎 SQL 语句的格式不正确。它没有找到执行 where 子句的表。
错误是:
PG::UndefinedTable: 错误:缺少表“items”第 1 行的 FROM 子句条目:SELECT COUNT() FROM "item_stores" WHERE ((CAST("items"."de... ^ : SELECT COUNT() FROM "item_stores" WHERE ((CAST("items"."description" AS VARCHAR) ILIKE '%b%' OR CAST("stores"."store_name" AS VARCHAR) ILIKE '%b %'))
我使用的模型位于其他两个之间,与每个模型具有多对一的关系: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...任何帮助将不胜感激。谢谢。
【问题讨论】:
-
谢谢。刚遇到同样的问题。文档中没有!
标签: ruby-on-rails jquery-datatables-rails