0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Merge pull request #2236 from sebgie/issue#2234

Fix importer adds the same tags to every post
This commit is contained in:
Hannah Wolfe 2014-02-22 16:39:40 +00:00
commit 54f0c3993f

View file

@ -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);