2017-06-05 3 views
0

私は今までに動作している列でコレクションのフェッチ結果を注文しようとしていますが、並べ替えで大文字小文字を区別しないようにします。私は本棚のドキュメントを見て、ここや他のフォーラムを無駄に探しました。生のKnex挿入が必要なものはありますか?どんな助けでも大歓迎です。ここでbookshelf orderBy ignore case

が私のコードです:

new Recipes().query('orderBy', 'name', 'asc').fetch({ 
    withRelated: [ 
    { instructions: (query) => { query.orderBy('step_number'); }}, 
    'tags', 
    'ingredients', 
    'ingredients.alternatives', 
    'ingredients.tags' 
    ] 
}); 

私のような何かをしたいと思います:

new Recipes().query('orderByIgnoreCase', 'name', 'asc').fetch({ 
    withRelated: [ 
    { instructions: (query) => { query.orderBy('step_number'); }}, 
    'tags', 
    'ingredients', 
    'ingredients.alternatives', 
    'ingredients.tags' 
    ] 
}); 

OR:

new Recipes().query('orderBy', LOWER('name'), 'asc').fetch({ 
    withRelated: [ 
    { instructions: (query) => { query.orderBy('step_number'); }}, 
    'tags', 
    'ingredients', 
    'ingredients.alternatives', 
    'ingredients.tags' 
    ] 
}); 

答えて

1

を以下のようにそれを試してみてください。

Recipes.query(function (qb) { 
    qb.orderByRaw('LOWER(name) asc'); 
}) 
.fetchAll({ 
    withRelated: [{ 
    'instructions': (query) => query.orderBy('step_number'), 
    'tags', 
    'ingredients', 
    'ingredients.alternatives', 
    'ingredients.tags' 
    }] 
}) 

またpostgresql sortingはOSに依存していることは注目に値する