Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created January 15, 2016 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crobinson42/5a0922e47f35e6d5dd9c to your computer and use it in GitHub Desktop.
Save crobinson42/5a0922e47f35e6d5dd9c to your computer and use it in GitHub Desktop.
SailsJs Querying Model Associations Workaround - using json attribute and find() 'contains'
module.exports = {
attributes: {
users : {
type : 'json',
defaultsTo : []
}
}
};
module.exports = {
attributes: {
reports : {
type : 'json',
defaultsTo : []
}
}
};
module.exports = {
// get records where this user is listed in Report models
findUserReportAssociations : function (req, res, next) {
var user = req.param('user'); // userId
Reports.find({ users : { 'contains' : user } }).exec(function(err, reportsWithUser) {
res.send(reportsWithUser);
});
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment