2016-09-29 53 views
0

我需要对相关表行上的MySQL数据库中的数据进行排序。js根据人口统计字段排序

假设我们有两种型号:

ModelOne:

module.exports = { 

    tableName: 'modelOne', 

    attributes: { 

    // some atributes......... 

    modelTwo{ 
     model: 'ModelTwo', 
     columnName: 'model_two_id' 
    } 
    } 
} 

ModelTwo:

module.exports = { 

    tableName: 'modelTwo', 

    attributes: { 
    // some atributes......... 

    model_two_id: { 
     type: 'integer', 
     autoIncrement: true, 
     primaryKey: true 
    }, 
    name: 'string' 
    } 
} 

我想这样做:

ModelOne 
    .find(find_criteria) 
    .populateAll() 
    .paginate({page: page, limit: limit}) 
    .sort('modelTwo.name') 
    .then(...) 

有没有可能性去做是或我需要编写SQL查询而不使用水线功能?

回答

0

这是我要做的事......

ModelOne 
    .find(find_criteria) 
    .populate('modelTwo', {sort: 'name ASC'}) 
    .paginate({page: page, limit: limit}) 
    .then(...) 

正如你所看到的,你可以通过{}排序对象来填充方法。