Sorting where()和sort()不适用于sail中填充的记录
我创建了一个Sails应用程序,其中有两个模型:Person和Department。 他们有一对一的关系。Sails-mysql是使用的适配器。当我尝试使用where()或sort()条件填充部门详细信息和人员时,结果记录未排序或where()未应用 Person.jsSorting where()和sort()不适用于sail中填充的记录,sorting,sails.js,waterline,populate,Sorting,Sails.js,Waterline,Populate,我创建了一个Sails应用程序,其中有两个模型:Person和Department。 他们有一对一的关系。Sails-mysql是使用的适配器。当我尝试使用where()或sort()条件填充部门详细信息和人员时,结果记录未排序或where()未应用 Person.js attributes: { firstname:{ alpha:true, required:true }, lastname:{
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(......);