我想在sequelize中关联3个表.
我创建的模型如下.
用户模型
var Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
uuid: {
type: Sequelize.STRING,
primaryKey: true
},
first_name: {
type: Sequelize.STRING,
allowNull: false
},
last_name: {
type: Sequelize.STRING,
allowNull: false
},
birth_date: {
type: Sequelize.DATE,
allowNull: false
},
gender: {
type: Sequelize.STRING,
allowNull: true
},
email_id: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isEmail: true
}
},
contact_number: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isNumeric: true
}
}
}, {
classMethods: { …Run Code Online (Sandbox Code Playgroud) 我在Sequelize中有一个位置模型
var Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
var Location = sequelize.define('Location', {
location_id: {
type: Sequelize.STRING,
primaryKey: true
},
location_code: {
type: Sequelize.STRING,
allowNull: true
},
location_name: {
type: Sequelize.STRING,
allowNull: true
},
latitude: {
type: Sequelize.STRING,
allowNull: true,
defaultValue: null
},
longitude: {
type: Sequelize.STRING,
allowNull: true,
defaultValue: null
},
location: {
type: Sequelize.GEOMETRY('POINT'),
allowNull: true
}
});
return Location;
};
Run Code Online (Sandbox Code Playgroud)
我通过喂入纬度和经度到位置
var location = { type: 'Point', coordinates: [latitude, longitude] };
Run Code Online (Sandbox Code Playgroud)
我有一个将纬度和经度作为参数的路由器。我需要在“位置”表中找出所提供的经度/纬度与所有位置之间的距离。
我该怎么做呢?Sequelize是否已经为我提供了确定距离的功能,还是需要编写外部查询来查找距离?
谢谢。
我有一个对象数组,我需要根据条件删除一些对象。如何使用lodash映射功能实现它?例如:
[{a: 1}, {a: 0}, {a: 9}, {a: -1}, {a: 'string'}, {a: 5}]
Run Code Online (Sandbox Code Playgroud)
我需要删除
{a: 0}, {a: -1}, {a: 'string'}
Run Code Online (Sandbox Code Playgroud)
我该如何实现?