I have a person model which has a belongsTo relations with a meeting model. I´m doing the query
Person.find({include:['meetings']})
Which gives me a result like this one:
person:{
name:"person 1",
age: 15
meeting:{
name: "The meeting",
date:"June 26, 2019 11:13:00"
}
}
What I would like to do is to order the results of the find function by the meeting date. Is there any way I can achieve this on a single query?
I´ve tried this:
Person.find({include:['meeting'],order:"meeting.date DESC"})
But server crashed when trying this. Can anyone help me achieve this?
Try this :
Person.find({
include:{
relation: 'meetings',
scope: {
order: 'date DESC'
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With