Hi, i'm a newbie with sequelize and i'm trying to execute a query to find users ordered by their distance from a specific point.
User.findAll({
attributes:[[Sequelize.literal('YEAR(CURRENT_TIMESTAMP) - YEAR(birthDay) - (RIGHT(CURRENT_TIMESTAMP, 5) < RIGHT(birthDay, 5))') , "age"]
,[Sequelize.literal('(DEGREES( ACOS( SIN( RADIANS( `latitude` ) ) ' +
'* SIN( RADIANS('+ lat +' ) ) + COS( RADIANS( `latitude` ) ) ' +
'* COS( RADIANS('+ lat +' ) ) ' +
'* COS( RADIANS('+ lng +' - `longtitude` ) ) ) ) * 69.09 * 1.6)') , "distance"],
'id', 'firstName' ,'lastName','nickname', 'gender'] ,
/* {model: model.Alias, as: 'aliases', attributes: ['name'], required: false},
where: ["'aliases.name' like ?", terms[0]+"%"],*/
limit:10,
offset:page * 10,
include:[{model:ProfileImage ,order:ProfileImage.order}],
where: ["User.id != ? AND gender != ?", userId , pref],
having:["distance < ? AND age BETWEEN ? AND ?", range , minAge, maxAge],
order:'distance , ProfileImages.order'
})
the problem is, the returned subset of 10 results is ordered by distance and not the whole table.
what am i doing wrong?