【发布时间】:2018-08-07 05:29:08
【问题描述】:
我在搜索时遇到问题,包括按距某个点的距离排序。这是我的代码和我正在尝试做的事情。感谢您的帮助
const Sequelize = require('sequelize');
var Flat = db.define('flat', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
}
});
var FlatAddress = db.define('flat_address', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
flat_id: {
type: Sequelize.INTEGER,
foreignKey:true,
allowNull:false,
references: {
model:'flats',
key: 'id'
}
},
city: {
type: Sequelize.STRING(50) //post_town
},
location: {
type: Sequelize.GEOMETRY('POINT')
}
});
Flat.hasOne(FlatAddress, { as: 'Address', foreignKey: 'flat_id', otherKey: 'id', onDelete: 'cascade' });
FlatAddress.belongsTo(Flat, { foreignKey: 'id', otherKey: 'flat_id', onDelete: 'cascade' });
我想做这样的事情
var POINT = {lat, lng} ??
Flats.findAndCountAll({
where: filter,
order: [
[ { model: FlatAddresses, as: 'Address' },
'//here should be something like distance from POINT//', 'ACS']
],
include: [
{ model: FlatAddresses, as: 'Address'}
],
offset,
limit
})
我没有找到适合我的案例的示例或文档。谢谢
【问题讨论】:
标签: javascript node.js postgresql sequelize.js postgis