Skip to content

Instantly share code, notes, and snippets.

@sdepold
Created September 14, 2012 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sdepold/3720242 to your computer and use it in GitHub Desktop.
Save sdepold/3720242 to your computer and use it in GitHub Desktop.
var chainer = new Sequelize.Utils.QueryChainer()
Artist.find({ where: {name: name} }).success(function(artist) {
if (artist) {
// get all tracks
artist.getTracks().success(function (tracks) {
if (tracks.length > 0) {
tracks.forEach(function(track) {
chainer.add(track.getArtists())
})
chainer.run().success(function(artists) {
for(var i = 0; i < tracks.length; i++) {
tracks[i].artists = artists[i]
}
res.render('artist', { title: artist.name, artist: artist, tracks: tracks });
})
} else {
res.render('artist', { title: artist.name, artist: artist, tracks: tracks });
}
});
} else {
req.flash('error', 'Artist not found');
res.redirect('/');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment