Created
January 15, 2016 20:03
-
-
Save crobinson42/5a0922e47f35e6d5dd9c to your computer and use it in GitHub Desktop.
SailsJs Querying Model Associations Workaround - using json attribute and find() 'contains'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
attributes: { | |
users : { | |
type : 'json', | |
defaultsTo : [] | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
attributes: { | |
reports : { | |
type : 'json', | |
defaultsTo : [] | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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