私はそれらの典型的なものを持っていますOrder
、LineItem
、Product
です。アソシエーションの列による注文はPostgreSQLではなく、PostgreSQLで動作します
Order
は、多くはLineItem
sであり、LineItem
はproduct_id
フィールドである。
という製品表の列に基づいて、Order
でLineItem
をソートしようとしています。
これはMySQLデータベース上ではローカルで動作しますが、PostgreSQLを使用する本番環境では動作しません。
scope :sort_by_product_id, -> {
includes(:product)
.order("products.code asc")
}
エラー:私はちょうど生産のjoins
の代わりincludes
が、それでも同じエラーと似て試してみました
ActionView::Template::Error (PG::SyntaxError: ERROR: syntax error at or near "products"
LINE 1: ..._id" WHERE "line_items"."order_id" = $1 ORDER BY products...
^
: SELECT "line_items".* FROM "line_items" INNER JOIN "products" ON "products"."id" = "line_items"."product_id" WHERE "line_items"."order_id" = $1 ORDER BY products.code asc):
。
してみてください: 'ディレクションを "{:コード=>:ASCは}" は無効です。有効な指示は:[:asc、:desc、:ASC、:DESC、 "asc"、 "desc"、 "ASC"、 "DESC"] 'です。そこにハッシュを渡すことはできないようだ。 – pzin
@pzin '.order(code::asc)'を試すことができますか?どのSQLを生成する? – itsnikolay
@larrylvによって提案された最初のオプションとして未知の 'line_items.code'列で注文しようとしています。 – pzin