Ruby on rails DataTables全局搜索中缺少FROM子句
我使用Ruby on rails DataTables全局搜索中缺少FROM子句,ruby-on-rails,jquery-datatables-rails,Ruby On Rails,Jquery Datatables Rails,我使用datatablesgem来显示包含两个相关表的表。结果,它从三个不同的表中拉入并显示列 这很好,我甚至可以按所需的列进行排序。不幸的是,全局搜索功能被破坏了。SQL语句的格式似乎不正确。它找不到执行where子句的表 错误是: PG::UndefinedTable:错误:表“items”第1行的子句条目中缺少:从“item_stores”中选择COUNT(),其中((CAST(“items.”de..^:从“item_stores”中选择COUNT(),其中((CAST(“items.”
datatables
gem来显示包含两个相关表的表。结果,它从三个不同的表中拉入并显示列
这很好,我甚至可以按所需的列进行排序。不幸的是,全局搜索功能被破坏了。SQL语句的格式似乎不正确。它找不到执行where子句的表
错误是:
PG::UndefinedTable:错误:表“items”第1行的子句条目中缺少:从“item_stores”中选择COUNT(),其中((CAST(“items.”de..^:从“item_stores”中选择COUNT(),其中((CAST(“items.”description“AS VARCHAR”)类似于“%b%”或CAST(“stores”。“store_name”类似于VARCHAR)类似于“%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…非常感谢您的帮助。谢谢。找到答案
get_raw_记录中的查询应为:
ItemStore.includes(:item,:store).引用(:item,:store)谢谢。只是遇到了同样的问题。文档中没有这个问题!添加引用似乎会破坏它。如果没有
引用
,页面将在2秒内加载,但在尝试搜索时抛出所描述的错误。使用引用
,它永远不会加载。我已经等了半个小时了。我想知道是否还有其他人如你所见