I've been struggling for hours to get the simplest populate() query working on my new sails.js project. The problem is that the field to populate always has an empty array. I've pored over the examples, so I don't think I have a syntax error, but maybe my tired eyes aren't letting me see.
Here are the two models + method that's making the query:
Model Department:
attributes: {
id: {
type: 'integer',
primaryKey: true
},
name: {
type: "string",
required: true
},
shortName: {
type: "string"
},
schoolName: {
model: 'Schools'
},
courses: {
collection: 'Courses',
via: "departmentId"
}
},
Model Courses:
attributes: {
id: {
type: "integer",
primaryKey: true
},
name: {
type: "string",
required: true
},
shortName: {
type: "string"
},
departmentId: {
model: "Departments"
}
},
And finally, the method making the call:
getDepartmentsBySchool: function(schoolName, callback){
Departments.find({schoolName: schoolName}).populate("courses").exec(function(error, departments){
if(error){
console.log("Departments could not be found");
return callback(error, []);
} else{
console.log(departments.length + " departments found");
return callback(null, departments);
}
});
}
Result:
courses: []
always.
I am using MySQL, so the adapter is sails-mysql. Any sort of pointer would be greatly appreciated so that I don't have to move away from using this framework.
EDIT:
Changing the migration to "alter" results in the following: