2015-04-04 30 views
1

我正在使用datatables gem來顯示包含兩個相關表的表。因此,它從三個不同的表中拉入並顯示列。使用DataTables全局搜索丟失FROM子句

這工作正常,我甚至可以根據需要的列進行排序。不幸的是,全球搜索功能被打破。看起來SQL語句沒有正確形成。它沒有找到表來執行where子句。

錯誤是:

PG::UndefinedTable: ERROR: missing FROM-clause entry for table "items" LINE 1: 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%'))

我使用的模型位於其他兩個之間,具有許多對1間的關係到各:項目(1) - (M)ItemStores(M) - (1- )存儲。

我的原始數據查詢:

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搜索...任何幫助將不勝感激。謝謝。

+1

感謝。剛剛有同樣的問題。這不在文檔中! – 2016-10-06 03:38:47

回答

2

找到了答案!

在get_raw_records查詢應閱讀:

ItemStore.includes(:項:存儲).references(:項:存儲)