Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Last active January 15, 2016 18:07
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/8f7976a6370a40ccefed to your computer and use it in GitHub Desktop.
Save crobinson42/8f7976a6370a40ccefed to your computer and use it in GitHub Desktop.
Sailsjs model association query
Report
.find({where: {users: "562ed24a11ea954b36f20f74" }})
.populate('users')
.exec(function (err, reports) {
console.log(reports);
});
module.exports = {
attributes: {
users : {
collection : 'user',
via : 'reports'
}
}
};
module.exports = {
attributes: {
reports : {
collection : 'report',
via : 'users'
}
}
};
@crobinson42
Copy link
Author

This is not working for me... no results

@mikermcneil
Copy link

This is not working for me... no results

will answer in gitter

@crobinson42
Copy link
Author

The solution here, advised by Mike McNeil, is to create a junction Model ie: ReportUser and use that model to reference the association.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment