2017-05-29 13 views
0

私は任意の初期順序を提示するためにcustom_orderを使用しようとしています。カスタム注文はSQL ORDER BYコードを無視します

# GET /sequences 
def index 
@sequences_grid = initialize_grid(Sequence, 
    enable_export_to_csv: false, 
       per_page: 10, 
      custom_order: { 
    'sequences.username' => "CASE WHEN username LIKE '#{current_user.username}' THEN 0 ELSE 1 END, username" 
         }, 
        name: 'seq_g1') 
end 

アイデアは、現在のユーザーのレコードをリストの一番上に置くことです。

ユーザーガイドには、「キーはデータベース列の完全修飾名であり、ORDER BY句で使用するSQLの必要なチャンクを評価する」と記載されています。

データベースエディタで実行するとSQLコードが正常に機能しますが、グリッドに必要な順序が表示されません。

ログは、任意のwice_grid問題について沈黙していると報告された要求は、次のとおりです。私はSQLコードが何らかの方法で壊されてもよいが、私は深く掘る前に、私は、誰かがぶつかったかもしれないと思ったことを疑う

10:10:35 web.1 | Sequence Load (0.3ms) SELECT distinct username FROM "sequences" ORDER BY username asc 
10:10:35 web.1 | Sequence Load (0.3ms) SELECT distinct classtype FROM "sequences" ORDER BY classtype asc 
10:10:35 web.1 | Sequence Load (0.2ms) SELECT distinct description FROM "sequences" ORDER BY description asc 
10:10:35 web.1 | Sequence Load (0.2ms) SELECT distinct sequencenumber FROM "sequences" ORDER BY sequencenumber asc 
10:10:35 web.1 | Sequence Load (0.2ms) SELECT distinct target FROM "sequences" ORDER BY target asc 
10:10:35 web.1 | Sequence Load (0.2ms) SELECT distinct indicator FROM "sequences" ORDER BY indicator asc 

同様の問題?

よろしく、 トム。

答えて

0

私は周りの猿の後、私はSQLがOKだったが、注文と同様にcustom_orderを指定する必要があることを発見した。

ユーザーガイドが少し誤解を招くように思われるので、例を提供しています...

@hosts_grid = initialize_grid(Host, 
    custom_order: { 
'hosts.ip_address' => 'INET_ATON(hosts.ip_address)' 
       }) 

が、例が提供...

@status_grid1 = initialize_grid(Status, 
    order: 'statuses.name', 
    custom_order: { 
    'statuses.name' => 'length(?)' 
    } 
) 

だから、次は私が必要なものをやりました...

# GET /sequences 
def index 
@sequences_grid = initialize_grid(Sequence, 
    enable_export_to_csv: false, 
       per_page: 10, 
       order: 'sequences.username', 
      custom_order: { 'sequences.username' => "CASE WHEN sequences.username LIKE '#{current_user.username}' THEN 0 ELSE 1 END, username, updated_at" }, 
     order_direction: 'desc', 
        name: 'seq_g1') 
end 

...つまり、現在のユーザーのレコードがlisteであるリストを作成しましたdが最初に降順で更新され、その後に他のユーザーのレコードが追加されます。

関連する問題