2017-06-05 96 views
0

我試圖通過一個工作到目前爲止我的集合獲取結果,但我希望排序是不區分大小寫的。我已經閱讀了書架文檔並在這裏和其他論壇搜索無濟於事。是否需要一些原始的Knex插入?任何幫助深表感謝。書架orderBy忽略大小寫

這裏是我的代碼:

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