小编Pra*_*kar的帖子

在SEQUELIZE中关联3个表

我想在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.js

6
推荐指数
1
解决办法
1178
查看次数

使用Sequelize和MySQL的地理空间距离计算器

我在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是否已经为我提供了确定距离的功能,还是需要编写外部查询来查找距离?

谢谢。

mysql geospatial latitude-longitude sequelize.js

4
推荐指数
1
解决办法
2475
查看次数

如何在lodash中删除数组中的对象

我有一个对象数组,我需要根据条件删除一些对象。如何使用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)

我该如何实现?

javascript node.js lodash

3
推荐指数
1
解决办法
3747
查看次数