I'm facing an issue with linking two models in sails. I have two models: 'Singer' and 'Country'. In the 'Singer' model, I have an attribute 'singer_country' which represents the id of the 'Country' model. My problem is that I am unable to retrieve the 'country_name' attribute from the 'Country' model when displaying all the properties of a singer. I'm not sure how to accomplish this. Below is my code: My 'Singer' model
module.exports = {
attributes: {
singer_name:{
type: 'string',
required: true,
size: 50
},
singer_realname:{
type: 'string',
size: 50
},
singer_gender:{
type: 'string',
enum: ['Male', 'Female'],
defaultsTo: 'Male'
},
singer_brithday:{
type: 'int'
},
singer_image:{
type: 'string'
},
singer_description:{
type: 'string'
},
singer_country:{
type: 'string'
}
}
};
My 'Country' model:
module.exports = {
attributes: {
country_name: {
type: 'string'
}
}
};
My method for displaying singer's properties:
index: function(req, res, next){
Singer.find().exec(function foundSinger(err, singerObj){
if(err) return next(err);
res.view({
singers: singerObj,
});
});
},
I am using MongoDB as my database, and I am working with sails beta 0.10 rc8. Any help would be greatly appreciated. Thank you.