diff --git a/core/server/data/fixtures/index.js b/core/server/data/fixtures/index.js index 354b853a30..6e955a806f 100644 --- a/core/server/data/fixtures/index.js +++ b/core/server/data/fixtures/index.js @@ -283,27 +283,36 @@ to004 = function to004() { // Add post_tag order upgradeOp = function () { - return models.Post.findAll(_.extend({}, options, {withRelated: ['tags']})).then(function (posts) { - var tagOps = []; + var tagOps = []; + logInfo('Collecting data on tag order for posts...'); + return models.Post.findAll(_.extend({}, options)).then(function (posts) { if (posts) { - posts.each(function (post) { - var order = 0; - post.related('tags').each(function (tag) { - tagOps.push((function (order) { - var sortOrder = order; - return function () { - return post.tags().updatePivot( - {sort_order: sortOrder}, _.extend({}, options, {query: {where: {tag_id: tag.id}}}) - ); - }; - }(order))); - order += 1; - }); + return posts.mapThen(function (post) { + return post.load(['tags']); }); } + return []; + }).then(function (posts) { + _.each(posts, function (post) { + var order = 0; + post.related('tags').each(function (tag) { + tagOps.push((function (order) { + var sortOrder = order; + return function () { + return post.tags().updatePivot( + {sort_order: sortOrder}, _.extend({}, options, {query: {where: {tag_id: tag.id}}}) + ); + }; + }(order))); + order += 1; + }); + }); + if (tagOps.length > 0) { - logInfo('Updating order on ' + tagOps.length + ' tags'); - return sequence(tagOps); + logInfo('Updating order on ' + tagOps.length + ' tag relationships (could take a while)...'); + return sequence(tagOps).then(function () { + logInfo('Tag order successfully updated'); + }); } }); };