如何通过sequelizejs中的include来使用orderBy

时间:2019-02-01 16:58:31

标签: include sql-order-by sequelize.js distance

我试图与被在运行时计算的查询和与别名名称

的列来获取结果
  

距离

这是我的查询

User.findAll({
      include: [{
        model: Address,
        attributes: ['col1',
          [Sequelize.literal("6371  acos(cos(radians(122))  cos(radians(latitude))  cos(radians(122) - radians(longitude)) + sin(radians(6661))  sin(radians(latitude)))"), 'distance']
        ],
      }],
      order: [Sequelize.literal("Address.distance"), 'DESC']
    });

但返回错误

  

未知列Address.distance

我也尝试过

User.findAll({
      include: [{
        model: Address,
        attributes: ['col1',
          [Sequelize.literal("6371  acos(cos(radians(122))  cos(radians(latitude))  cos(radians(122) - radians(longitude)) + sin(radians(6661))  sin(radians(latitude)))"), 'distance']
        ],
      }],
      order: ["distance", 'DESC']
    });

但它给出了相同的错误:

  

未知列距离

任何人都可以在这件事上提供帮助。 预先感谢

2 个答案:

答案 0 :(得分:0)

尽量明确指定由您要排序的模型。

.intel_syntax noprefix

.global _start

.data
    a: .double 4.56   # length of side a
    b: .double 7.89   # length of side b
    ang: .double 1.5  # opposite angle to side c (around 85.94 degrees)

.lcomm c, 8

.text
    _start:

    fld qword ptr [a]   # load a into st0
    fmul st             # st0 = a * a = a^2

    fld qword ptr [b]   # load b into st0
    fmul st             # st0 = b * b = b^2

    faddp               # st0 = a^2 + b^2

    fld qword ptr [ang] # load angle into st0
    fcos                # st0 = cos(ang)

    fmul qword ptr [a]  # st0 = cos(ang) * a
    fmul qword ptr [b]  # st0 = cos(ang) * a * b
    fadd st             # st0 = cos(ang) * a * b + cos(ang) * a * b = 2(cos(ang) * a * b)

    fsubp               # st1 = st1 - st0 = (a^2 + b^2) - (2 * a * b * cos(ang))
                        # and pop st0

    fsqrt               # take square root of st0 = c

    fstp qword ptr [c]  # store st0 in c - and we're done!

    # end program
    mov eax, 1
    xor ebx, ebx
    int 0x80

答案 1 :(得分:0)

您可以在属性中描述的距离后按距离排序

field.name