diff --git a/core/server/models/post.js b/core/server/models/post.js index 1deb5640ea..66de0722c4 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -11,8 +11,7 @@ var _ = require('lodash'), ghostBookshelf = require('./base'), Post, - Posts, - myTags; + Posts; Post = ghostBookshelf.Model.extend({ @@ -50,7 +49,7 @@ Post = ghostBookshelf.Model.extend({ var self = this; // keep tags for 'saved' event - myTags = this.get('tags'); + this.myTags = this.get('tags'); ghostBookshelf.Model.prototype.saving.call(this); @@ -92,9 +91,10 @@ Post = ghostBookshelf.Model.extend({ updateTags: function (newPost, attr, options) { /*jslint unparam:true*/ + var self = this; options = options || {}; - if (!myTags) { + if (!this.myTags) { return; } @@ -108,7 +108,7 @@ Post = ghostBookshelf.Model.extend({ // First find any tags which have been removed _.each(existingTags, function (existingTag) { - if (!_.some(myTags, function (newTag) { return newTag.name === existingTag.name; })) { + if (!_.some(self.myTags, function (newTag) { return newTag.name === existingTag.name; })) { tagsToDetach.push(existingTag.id); } }); @@ -118,7 +118,7 @@ Post = ghostBookshelf.Model.extend({ } // Next check if new tags are all exactly the same as what is set on the model - _.each(myTags, function (newTag) { + _.each(self.myTags, function (newTag) { if (!_.some(existingTags, function (existingTag) { return newTag.name === existingTag.name; })) { // newTag isn't on this post yet tagsToAttach.push(newTag);