I'm trying to define a custom attribute in my sails model and I want to access a certain field in a related table how do I do this in sails? Please check my sample code below
Example:
// models/User.js
attributes: {
name: 'string',
...
// now define the realtionship
school: { model: 'School' },
// define custom attribute
studyIn: function(){
// returns nothing
return this.school.name ;
}
}
// models/School.js
attributes: {
name: 'string',
address: 'string',
students: { collection: 'User', via: 'school' }
}
Thanks