lib/models/posts_tags.js
function postSetTags(post_id, tags, cb) {
  var ids = _.pluck(tags, 'id')
    , q1 = 'DELETE FROM posts_tags WHERE post_id = $1'
    , q2 = 'INSERT INTO posts_tags (post_id, tag_id) VALUES ' +
    ids.map(function(id) {
      return '(' + post_id + ',' + id + ')';
    }).join(', ');

  db.getClient(function(err, client, done) {
    client.query(q1, [post_id], function(err, r) {
      if(err) { return cb(err); }
      client.query(q2, function(err, r) {
        if(err) {
          cb(err);
          done(err);
        } else {
          cb(null, r.rowCount);
          done();
        }
      });
    });
  });
}
function postSetTags(post_id, tags, cb) {
  var ids = _.pluck(tags, 'id')
    , q1 = 'DELETE FROM posts_tags WHERE post_id = $1'
    , q2 = 'INSERT INTO posts_tags (post_id, tag_id) VALUES ' +
    ids.map(function(id) {
      return '(' + post_id + ',' + id + ')';
    }).join(', ');

  db.getClient(function(err, client, done) {
    client.query(q1, [post_id], function(err, r) {
      if(err) { return cb(err); }
      client.query(q2, function(err, r) {
        if(err) {
          cb(err);
          done(err);
        } else {
          cb(null, r.rowCount);
          done();
        }
      });
    });
  });
}
function postSetTags ( post_id , tags , cb ) { var ids = _ . pluck ( tags , 'id' ) , q1 = 'DELETE FROM posts_tags WHERE post_id = $1' , q2 = 'INSERT INTO posts_tags (post_id, tag_id) VALUES ' + ids . map ( function ( id ) { return '(' + post_id + ',' + id + ')' ; } ) . join ( ', ' ) ; db . getClient ( function ( err , client , done ) { client . query ( q1 , [ post_id ] , function ( err , r ) { if ( err ) { return cb ( err ) ; } client . query ( q2 , function ( err , r ) { if ( err ) { cb ( err ) ; done ( err ) ; } else { cb ( null , r . rowCount ) ; done ( ) ; } } ) ; } ) ; } ) ; }
Removes existing association and associates `tags` with post with id `post_id`

@param {Number} post_id
@param {Array} tags
@param {Function} cb
Removes existing association and associates tags with post with id post_id