sorting - where() 和 sort() 不适用于 sails 中填充的记录

标签 sorting sails.js waterline populate

我创建了一个包含两个模型 Person 和 Department 的 Sails 应用程序。 他们有一对一的关系。Sails-mysql 是使用的适配器。当我尝试使用 where() 或 sort() 标准填充部门详细信息以及 Person 时,结果记录未排序或 where() 是不适用。

Person.js

attributes: {
firstname:{
            alpha:true,
            required:true
        },
        lastname:{
            alpha:true,
            required:true
        },
        age:{
            numeric:true,
            required:true
        },
        department:{
            model:'Department'
        }
  }

Department.js

attributes: {
DepartmentName:{
        required:true,
        alpha:true
  },
  Description:{
        required:true,
        alpha:true
  },
  //relation
  person:{
      model:'Person'
  }

PersonController.js

Person.find().populate('department').where({DepartmentName:{"startsWith":"hr"}}).sort('Description desc').exec(console.log);

不工作。

我以所有可能的方式尝试了 where() 和 sort()

var sort='DepartmentName desc';

并在 populate() 中传递该变量,如下所示:

Person.find().populate('department',sort).exec(console.log);

但这也不起作用。以同样的方式我尝试了 where() 也是失败的。

帮帮我。

最佳答案

对我来说这是有效的 ;)

Person.find().populate('department', {
                where: {
                    DepartmentName: {
                        'startsWith': 'hr'
                    }
                },
                sort: 'DepartmentName desc'}
            ).exec(......);

有关更多信息,请查看此处:http://sailsjs.org/documentation/reference/waterline-orm/queries/populatePopulating a collection association

部分下

关于sorting - where() 和 sort() 不适用于 sails 中填充的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33096600/

相关文章:

mysql - 为什么 sails.js 启动失败?

node.js - 使用 Sails.js 进行全文搜索

mysql - 无法使用 Sailsjs 适配器连接 aws rds

mysql - 如何查找未与 Waterline ORM 连接的记录

android - socket.io Android 库认证

javascript - 为什么冒泡排序的 Javascript 实现比其他排序算法快得多?

algorithm - 选择排序顺序

javascript - SailsJS/水线 ORM : Update multiple entries using only one query

javascript - 根据时间和组对数组进行排序

java - 在java中对字符串进行排序