두 개의 모델 Publication 및 Worksheet로 Sails 애플리케이션을 만들었습니다. 그들은 일대일 관계를 맺고 있습니다. Sails-postgresql은 제가 사용하고있는 어댑터입니다. 난 물 라인 orm을 사용하여 데이터베이스에 쿼리를 실행하고 있습니다. 나는 워크 시트와 함께 발행물 데이터를로드하려고 할 때 sort()를 사용하여 워크 시트의 필드에 따라 레코드를 정렬하려고 할 때 오류가 발생합니다.돛에 채워진 레코드 정렬
내 모델은 다음과 같습니다
Publication.js
module.exports = {
attributes: {
id: {
type: 'integer'
unique: true
},
worksheetId: {
type: 'integer',
model : 'worksheet'
},
status: {
type: 'string',
defaultsTo: 'active',
in : ['active', 'disabled'],
}
}
}
Worksheet.js
module.exports = {
attributes: {
id: {
type: 'integer',
unique: true
},
name: 'string',
orderWeight: {
type: 'integer',
defaultsTo: 0
}
}
}
그래서 지금은 상태가 "활성"여기서 모든 출판물을로드하고 워크 시트를 채우려 데이터에.
Publication.find({
where: {
status: 'active'
}
})
.populate('worksheetId').limit(1)
.exec(function (error, publications) {
})
을 그리고 난 같은 데이터를 받고 있어요 :
은 그래서 쿼리를 실행하고있어 지금은 모든 작업 괜찮까지 그래서{
id : 1,
status : "active",
worksheetId : {
id : 1
name : "test",
orderWeight : 10
}
}
. 이제 한계를 10으로 늘리고 채워진 데이터에있는 "orderWeight"에 따라 데이터를 정렬하려고합니다. 처음에는 게시 ID와 쿼리에 따라 전체 데이터를 정렬했습니다.
Publication.find({
where: {
status: 'active'
}
})
.populate('worksheetId').sort('id ASC').limit(10)
.exec(function (error, publications) {
})
그래서 나는 "orderWeight"
Publication.find({
where: {
status: 'active'
}
})
.populate('worksheetId').sort('worksheetId.orderWeight ASC').limit(10)
.exec(function (error, publications) {
})
의 데이터를 정렬하는 유사한 쿼리를 해고 그리고이 쿼리는 worksheetId.orderWeight가 게시 테이블에 열이 아니라고 나에게 오류를주고있다. 그래서 게시 테이블에없는 채워진 데이터에 대해이 정렬 쿼리를 실행하려고합니다.
제 기대 결과를 얻을 수있는 방법을 알려주세요.
sort() 메서드 외에도 채워진 데이터에 대해 find 명령을 실행하여 워크 시트 이름이 특정 키와 일치하는 게시를 얻고 싶습니다.