2014-09-02 59 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)