如何在PostgreSQL

时间:2016-04-29 11:32:11

标签: ruby-on-rails postgresql

如何将orderuniq一起使用?

auction.invoices.get_auction_invoices.item_invoices.
joins("INNER JOIN users ON users.id = invoices.usable_id").order("users.first_name").uniq

以上查询给出了以下错误:

这是我的范围

范围:item_invoices, - > {joins(:invoice_details).where(" invoice_details.invoiceable_type =?"," Item")}

范围:get_auction_invoices, - > {where(:id =>(item_invoices.skip_cancelled_invoice + donators.skip_cancelled_invoice))}

  

PG :: InvalidColumnReference:错误:对于SELECT DISTINCT,ORDER BY表达式必须出现在选择列表中   第1行:... oice_details.invoiceable_type ='项目')ORDER BY users.firs ...   :SELECT DISTINCT"发票"。* FROM"发票" INNER JOIN" invoice_details" ON" invoice_details"。" invoice_id" ="发票"。" id" INNER JOIN用户ON users.id = invoices.usable_id WHERE"发票"。" eventable_id" = $ 1 AND"发票"。" eventable_type" = $ 2 AND"发票"。" id" IN(1132,1131,777,777,777,3013,3024,3024,3024,3024,3041,3041,3013)AND(invoice_details.invoiceable_type =' Item')ORDER BY users.first_name

1 个答案:

答案 0 :(得分:1)

试试这个:

auction.invoices.get_auction_invoices.item_invoices.\
select("invoices.*, users.*").\
joins("INNER JOIN users ON users.id = invoices.usable_id").\
order("users.first_name").\
uniq