2014-09-02 61 views
0

我試圖通過我的產品postgres表循環,然後顯示連接了回形針圖像的前5個,但沒有任何查詢正在工作。在我的產品型號回形針附件被稱爲photo_image_file,photo_file_name,photo_content_type等PostgreSQL檢查是否存在回形針附件

下面是代碼行:

<% featured = Product.order('created_at DESC').limit(5).where("photo_file_name?") %> 

什麼是正確的PostgreSQL的查詢做到這一點?它只需要返回一個真正的布爾值。

+0

試試這個:'在哪裏( 「photo_file_name IS NOT NULL」)' – MrYoshiji 2014-09-02 17:06:44

回答

0

嘗試以下操作:

Product.where.not(photo_file_name: nil).limit(5).order(created_at: :desc)