Skip to content

Instantly share code, notes, and snippets.

@durango
Forked from sdepold/gist:3720242
Created September 19, 2012 19:01
Show Gist options
  • Select an option

  • Save durango/3751520 to your computer and use it in GitHub Desktop.

Select an option

Save durango/3751520 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